Azure / Azure/data-api-builder
[Bug]: GraphQL mutation does not properly handle variables
- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 370
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 8
Description
### What happened?
Description:
I've been using the DataApiBuilder with a StaticWebApp in production, and I've encountered an issue where the GraphQL mutation does not correctly handle variables when sent in a request. Instead of using the provided variable values, the mutation uses the variable names themselves as the field values.
To reproduce the issue, I used the following GraphQL mutation as an example:
```graphql
mutation CreateExample($id: ID!, $name: String!) {
createExample(
item: {
id: $id,
name: $name
}
) {
id
name
}
}
```
And the variables:
```json
{
"id": "1234",
"name": "Test Example"
}
```
When I send this mutation using a JSON payload in a POST request to the DataApiBuilder, the server incorrectly stores the values as "id" and "name" instead of the provided values "1234" and "Test Example".
I was able to reproduce this issue using Postman, and it seems to be a bug in the DataApiBuilder code. Could you please investigate this issue and provide guidance on how to resolve it?
Steps to reproduce:
1. Set up a StaticWebApp with DataApiBuilder as the backend.
2. Define the schema for the GraphQL mutation as shown above.
3. Send a POST request with the JSON payload containing the mutation and variables.
4. Observe the incorrect handling of variables in the server response and stored data.
Expected behavior:
The GraphQL mutation should properly handle variables and store the provided values in the corresponding fields.
Actual behavior:
The GraphQL mutation uses the variable names as the field values, not the actual variable values provided.
Thank you for looking into this issue.
### Version
0.6.14+b21a924c4a9220e9cdef36032786b531c6394251
### What database are you using?
CosmosDB NoSQL
### What hosting model are you using?
Local (including CLI), Static Web Apps (SWA)
### Which API approach are you accessing DAB through?
GraphQL
### Relevant log output
_No response_
### Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Contributor guide
Assessment
This issue has not been assessed yet.