Consider a GraphQL API that supports transactions with the following operations:
mutation {
startTransaction {
transactionId
}
}
mutation {
updateUser(id: 1, name: "Alice") {
id
name
}
}
mutation {
commitTransaction(transactionId: "tx123") {
success
}
}Assuming the updateUser mutation is executed within the transaction started, what will be the final name of the user with id 1 after commit?
Think about what commitTransaction does in a transaction context.
In transaction handling, changes made inside a transaction are only visible after the transaction is committed. So the user's name changes to "Alice" after commitTransaction succeeds.
Which of the following GraphQL mutations correctly starts a transaction?
Recall the correct syntax for GraphQL mutations and field selection.
Option D uses the correct syntax: mutation keyword, braces, and selection set. Other options have syntax errors like missing braces or invalid argument usage.
You want to update multiple user records atomically using GraphQL transactions. Which approach is best to minimize transaction overhead?
Think about how transactions reduce overhead when grouping operations.
Starting one transaction and committing once after all updates reduces overhead and ensures atomicity. Multiple transactions increase overhead and risk partial updates.
Given this sequence:
mutation { startTransaction { transactionId } }
mutation { updateUser(id: 2, name: "Bob") { id name } }
mutation { rollbackTransaction(transactionId: "tx999") { success } }The updateUser mutation is executed, but the rollbackTransaction uses a wrong transactionId. What happens to the update?
Consider what happens if rollbackTransaction targets a non-existent transaction.
If rollbackTransaction fails due to wrong transactionId, the transaction remains active or committed depending on implementation. Usually, changes are committed or remain visible after mutation if rollback fails.
In a GraphQL API supporting transactions, what does the isolation level control?
Think about what isolation means in database transactions.
Isolation level defines how and when changes made in one transaction become visible to others, preventing issues like dirty reads or phantom reads.