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.

Mutations are not working with Apollo Client : passing variables

See original GitHub issue

I am using an Angular Client with angular-apollo https://apollo-angular.com/docs/data/mutations and Mutations are throwing an error even though the variables are passed.

This is with Cosmos DB as storage.

Client Code :

const post_SaveHero = gql`
mutation ($id : String!, $publisher : String!, $superhero :String!, $characters:String!){
  addHero(id : $id , publisher : $publisher , superhero : $superhero , characters: $characters )
 {
  superhero
}
}`;

Invoking it as,

  updateHero(hero: Hero){
    console.log("$$$HERO",hero.id);
    console.log("$$$HERO OBJECT",JSON.stringify(hero));
    return this.apollo.mutate({
      mutation: post_SaveHero,
      variables: {
        id: hero.superhero,
        publisher: hero.publisher,
        superhero: hero.superhero,
        characters: hero.characters
      }
    }
    );
  }

and the error thrown as,

Screenshot at Mar 14 21-17-01

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
aaronpowellcommented, Mar 17, 2022

@sajeetharan - did this work with #290 merged to main?

0reactions
aaronpowellcommented, Aug 9, 2022

I’ve started digging down a rabbit hole of how we parse the variables and arguments in the runtime and what I’ve found is that we have several methods that do it and not all engines process them in the same way.

So, I went back to the HotChocolate source to see if we’d missed something in the parsing, since it has to handle variables itself, and found that they have a method that will get the arguments with variables - https://github.com/ChilliCream/hotchocolate/blob/main/src/HotChocolate/Core/src/Execution/Internal/ArgumentCoercionHelper.cs#L12

I’m going to have a look at refactoring to use that method, which will mean that we can move away from IDictionary<string, object?> for the parameters in the execution engines and have something that is more strongly typed, and the runtime to do less manual processing of the args/variables/etc., instead, just walk the complete graph when it’s time to execute a request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client
Here, we use the variables option to provide the values of any GraphQL variables that our mutation requires (specifically, the type of the...
Read more >
Passing a variable to GraphQL mutation using ApolloClient ...
I'm trying to figure out how to run mutations using Apollo Client. Here's the mutation I'm trying to run: export const CREATE_POST =...
Read more >
Mutations - Apollo GraphQL Docs
If a mutation modifies multiple entities, or if it creates or deletes entities, the Apollo Client cache is not automatically updated to reflect...
Read more >
apolloClient.mutate variables not working · Issue #2762
Intended outcome: Variable merged into the mutation ; Actual outcome: Status: 400 error with variable, and the mutation works when hard-coding ...
Read more >
How to use GraphQL mutations in React and Apollo Client
Mutations in GraphQL are responsible for saving the data. Apollo Client offers mechanisms that make working with mutations.
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