Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic update: Error at path "<query_with_pagination>.nextToken": missingValue #51

Closed
richienko opened this issue Jul 27, 2018 · 10 comments

Comments

@richienko
Copy link

richienko commented Jul 27, 2018

The query with argument within optimistic update closure will fail with "missingValue" message.
The query is paginated.

Version of AppSync:
2.6.18

Message I'm getting:
Error at path "listJobsByCustomer.nextToken": missingValue

Mutation:
updateJob(input: UpdateJobInput!): Job

Query called in optimistic update closure:
listJobsByCustomer(customerId: String, first: Int, after: String): JobConnection

JobConnection:

type JobConnection {
	items: [Job]
	nextToken: String
}

Code:

let mutation = UpdateJobMutation(input: input)

appSyncClient?.perform(mutation: mutation, optimisticUpdate: { (transaction) in
	do {
		// Update our normalized local store immediately for a responsive UI
		let query = ListJobsByCustomerQuery(customerId: "customerId", limit: 1)
		try transaction?.update(query: query) {
			(data: inout ListJobsByCustomerQuery.Data) in

			for i in 0..<(data.listJobsByCustomer?.items)!.count {
				if data.listJobsByCustomer?.items?[i]?.id == input.id {
					data.listJobsByCustomer?.items?[i]?.status = input.status!
				}
			}
		}
	} catch let exception {
		print("UpdateJobMutation Error updating the cache with optimistic response: \(exception.localizedDescription)")
	}
}) { (result, error) in
	if let error = error as? AWSAppSyncClientError {
		print("Error occurred: \(error.localizedDescription )")
		return
	}
	
	if let res = result {
		print("UpdateJobInfo result: \(res)")
	}
	
	self.handleNetworkStateOnResult(online: true)
}
@wir349
Copy link

wir349 commented Jul 27, 2018

I'm having a similar issue, except I'm not using pagination.

@koingruc
Copy link

koingruc commented Aug 2, 2018

Is this bug is fixed in Release v2.6.18 ? Thanks

@richienko
Copy link
Author

@koingruc no, it's not fixed, I'm using 2.6.18 and it's bugged

@koingruc
Copy link

koingruc commented Aug 3, 2018

@richienko Thank you for the information. Hope it is fixed soon

@ghost
Copy link

ghost commented Aug 15, 2018

Same issue. Simply trying to implement a basic mutation with the sample code provided on the official doc page, yet getting "missingValue" from transaction?.update.

@koingdev
Copy link

koingdev commented Aug 21, 2018

For those who have problem with optimistic UI missing value. I've found one trick to temporary solve the issue by passing parameter using Custom Request Header from client app.
Before, your query would look like this allDiaries(author: String): [Diary]
Just change it to => allDiaries: [Diary]
So your request mapping would look like below:

{
    "version" : "2017-02-28",
    "operation" : "Scan",
    "filter" : {
        "expression" : "author = :author",
        "expressionValues" : {
            ":author" : { "S" : "$context.request.headers.author" }
        }
    }
}

Reference: https://stackoverflow.com/questions/51932849/how-to-pass-aws-appsync-custom-request-header-in-ios-client/51950574#51950574
Hope it is useful! Goodluck :)

@hemant236
Copy link

Any update on the issue, Is it fixed in latest 2.6.21

@koingruc
Copy link

koingruc commented Sep 13, 2018

@hemant236 It is not yet fixed. You can check the changelog.
https://github.com/awslabs/aws-mobile-appsync-sdk-ios/blob/master/CHANGELOG.md
If you have this issue, you can try my solution :) I solved it using Request Header instead of Argument

@hemant236
Copy link

hemant236 commented Sep 13, 2018

@koingruc Is there any other framework/class that I need to import for using CognitoAuthProvider() and CognitoUserPoolManager?
Use of unresolved identifier 'CognitoUserPoolManager'

@rohandubal
Copy link
Contributor

This is now fixed with SDK Version 2.6.22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants