question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: GraphQL mutation does not properly handle variables

See original GitHub issue

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:

mutation CreateExample($id: ID!, $name: String!) {
  createExample(
    item: {
      id: $id,
      name: $name
    }
  ) {
    id
    name
  }
}

And the variables:

{
  "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

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:open
  • Created 4 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ChrMaasscommented, May 17, 2023

Thanks @tarazou9, but everything fine. Hope you find the bug 😃

0reactions
ChrMaasscommented, Jun 24, 2023

Anything new?

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL bug- mutations - simple mutation not working ...
The short answer is that currently only scalar variables are supported and things break if you pass an "input object" as a variable....
Read more >
graphql error: mutation with where not working
1 Answer 1 ... Your mutation has the two parameters data and where, but you expect the parameter list { id, name, email,...
Read more >
Mutations in Apollo Client
Specifies how the mutation handles a response that returns both GraphQL errors and partial results. For details, see GraphQL error policies. The default...
Read more >
useMutation | TanStack Query Docs
The mutation function you can call with variables to trigger the mutation and optionally hooks on additional callback options. variables: TVariables. Optional ...
Read more >
GraphQL Queries and Mutations with useSWR - Episode #58
Today we'll look at using SWR to fetch, and mutate a basic cache. It's not going to be as complex as the dedicated...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found