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.

$input syntax in the codegen mutations is not working with graphqlOperations.

See original GitHub issue

Describe the bug Running amplify codegen creating mutations not supported by amplify graphqlOperations

To Reproduce amplify codegen creates mutations like this:

export const CreateCity = gql`
  mutation CreateCity($input: CreateCityInput!) {
    createCity(input: $input) {
      id
      city_name
      zip_code
    }
  }
`;

However when I try to use it via this : ` API.graphql(graphqlOperation(gqlToString(fp_mutations.CreateCity, {id: {city_name:city_name,zip_code:zip_code}})))

I get an error path: null, locations: Array(1), message: “Variable ‘input’ has coerced Null value for NonNull type ‘CreateCityInput!’”

However if I change the mutation by hand to something like this : export const CreateCity = mutation createCity($city_name: String!, $zip_code: String!) { createCity(input: {city_name: $city_name, zip_code: $zip_code}) { id, city_name, zip_code } }; ` and call it like this

API.graphql(graphqlOperation(gqlToString(fp_mutations.CreateCity, {city_name:city_name,zip_code:zip_code})))

it works! It seems that the ($input syntax in the codegen mutations is not working with graphqlOperations.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
yuthcommented, Oct 24, 2018

@lahirian the mutation expects an input object which wraps city_name and zip_code. The update code would look like below:

API.graphql(
  graphqlOperation(
    gqlToString(fp_mutations.CreateCity, {
      input: {
        city_name: city_name,
        zip_code: zip_code
      }
    })
  )
);

0reactions
github-actions[bot]commented, May 27, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript with Apollo Client - Apollo GraphQL Docs
We'll use our generated types to ensure type safety for the inputs and results of our GraphQL operations. Below, we'll guide you through...
Read more >
API (GraphQL) - Fetch data - JavaScript - AWS Amplify Docs
The API category provides a GraphQL client for working with queries, mutations, and subscriptions. Query Declarations. The Amplify CLI codegen automatically ...
Read more >
typescript-operations - GraphQL Code Generator
yarn add -D @graphql-codegen/typescript-operations ... Without loading your GraphQL operations ( query , mutation , subscription and ...
Read more >
Mutations and Input Types - GraphQL
If you have an API endpoint that alters data, like inserting data into a database or altering data already in a database, you...
Read more >
How to do filteration in AWS Amplify GraphQL Client
I think I have an answer to your question, but I also have a similar question regarding the AWS Amplify codegen queries, 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