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.

buildMutation not working properly

See original GitHub issue

I’m trying to use buildMutation, and it doesn’t seem to be working correctly. I’m also confused by the discrepancy between docs and source.

The Amplify API docs say to do this:

  const result = await client.mutate(buildMutation(client,
    gql(createStudent),
    {
      inputType: gql(CreateStudentInput),
      variables
    },
    (_variables) => [ gql(listStudents) ],
    'Student'
  ));

but by looking at the source code it looks like I should do this:

  const result = await client.mutate(buildMutation(
      client,
      gql(createStudent),
      variables,
      gql(listStudents),
      'Student'
  ))

Here’s what happens using the second code sample

  1. I initiate create on a Student named ‘Bob’

  2. (In another component) The listStudents query returns an empty data.listStudents while the mutation is in flight.

  3. Once the server returns success, then listStudents returns a full data.listStudents including the new record.

  4. Console shows a bunch of errors like

 Missing field bookMaps in {
  "__typename": "Student",
  "id": "30128546-4592-4833-852f-1bdddba858ce",
  "firstName": "Bob"
My `createStudent` mutation
export const createStudent = `mutation CreateStudent($input: CreateStudentInput!) {
  createStudent(input: $input) {
    id
    firstName
    lastName
    birthdate
    curriculumMaps {
      items {
        id
      }
      nextToken
    }
    bookMaps {
      items {
        id
      }
      nextToken
    }
    resourceMaps {
      items {
        id
      }
      nextToken
    }
    summaryMaps {
      items {
        id
      }
      nextToken
    }
  }
}`

My `listStudents` query
export const listStudents = `query ListStudents(
  $filter: ModelStudentFilterInput
  $limit: Int
  $nextToken: String
) {
  listStudents(filter: $filter, limit: $limit, nextToken: $nextToken) {
    items {
      id
      firstName
      lastName
      birthdate
      curriculumMaps {
        nextToken
      }
      bookMaps {
        nextToken
      }
      resourceMaps {
        nextToken
      }
      summaryMaps {
        nextToken
      }
    }
    nextToken
  }
}
`

Versions

"aws-appsync": "1.7.1",
"aws-appsync-react": "1.2.6",

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
santi8194commented, Jun 5, 2020

Any update here? It’s been a year and a half since this issue has any comments. And today, I’m having the same problems, the documentation is the same and I can’t find any solution.

3reactions
flybayercommented, Feb 4, 2019

Update: buildMutation is never updating the cache, even after a successful API response. I thought this was working earlier, but I forgot to comment out my refetch() while testing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - Getting With helper for offline capabilities to work
E.G. A variable named client will not be globally available so you need to grab a handle to it. Looking at the Apollo...
Read more >
Mutations | Redux Toolkit
The useMutation hook returns a tuple containing a "mutation trigger" function, as well as an object containing properties about the "mutation ...
Read more >
"Throttled" Error Message on CheckoutCreate mutation
Anyways, one massive problem that's plagued the. ... message and have any ideas to use the queueToken possibly to properly deal with it?...
Read more >
Any good Y.V. build/mutation guides? : r/NuclearThrone - Reddit
since Y.V's active doesn't work very well with automatic weapons. ... focuses on a good melee weapon (more often than not the Energy...
Read more >
react unchecked runtime.lasterror: the message port closed ...
The problem is that extension can not be disabled on my office computer :)) ... I've built it by watching a youtube tutorial...
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