buildMutation not working properly
See original GitHub issueI’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
-
I initiate create on a Student named ‘Bob’
-
(In another component) The
listStudents
query returns an emptydata.listStudents
while the mutation is in flight. -
Once the server returns success, then
listStudents
returns a fulldata.listStudents
including the new record. -
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:
- Created 5 years ago
- Reactions:4
- Comments:11 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 myrefetch()
while testing this.