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

Error updating store in subscription result handler #101

Closed
huforrest opened this issue Nov 15, 2018 · 5 comments
Closed

Error updating store in subscription result handler #101

huforrest opened this issue Nov 15, 2018 · 5 comments
Assignees
Labels
bug Something isn't working closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made.

Comments

@huforrest
Copy link

huforrest commented Nov 15, 2018

I subscribed to a new message subscription. When I get the new data and prepare to update the local store with the newly received data, I get an error. Here is the error log:

GraphQLResultError(path: ["allMessageConnection"], underlying: AWSAppSync.JSONDecodingError.missingValue)

And here is my code:

func startNewMessageSubscription() {
        let subscription = SubscribeToNewMessageSubscription(conversationId: conversationId)
        print("Starting new post subscription")
        do {
            newMessageSubscriptionWatcher = try appSyncClient?.subscribe(subscription: subscription, resultHandler: { (result, transaction, error) in
                print("Received new post!")
                if let result = result {
                    // Store a reference to the new object
                    let newMessage = result.data!.subscribeToNewMessage!
                    // Create a new object for the desired query where the new object content should reside
                    let messageToAdd = GetConversationMessagesQuery.Data.AllMessageConnection.Message(id: newMessage.id, conversationId: newMessage.conversationId, content: newMessage.content, createdAt: newMessage.createdAt, sender: newMessage.sender, isSent: newMessage.isSent)
                    do {
                        // Update the local store with the newly received data
                        try transaction?.update(query: GetConversationMessagesQuery(conversationId: newMessage.conversationId)) { (data: inout GetConversationMessagesQuery.Data) in
                            data.allMessageConnection?.messages?.append(messageToAdd)
                        }
                        self.loadAllMessagesFromCache(conversationId: newMessage.conversationId)
                    } catch let error {
                        print("Error updating store: \(error)")
                    }
                } else if let error = error {
                    print(error.localizedDescription)
                }
            })
        } catch {
            print("Error starting subscription.")
        }
    }

The error lies in this line:
data.allMessageConnection?.messages?.append(messageToAdd)

@frankmuellr frankmuellr added AppSync question A question about how to use an existing feature labels Nov 15, 2018
@rohandubal rohandubal assigned palpatim and unassigned rohandubal Dec 11, 2018
@palpatim
Copy link
Contributor

This seems related to #92, at least based on the "missing value" message.

@palpatim palpatim added bug Something isn't working and removed question A question about how to use an existing feature labels Jan 21, 2019
@palpatim palpatim changed the title Error updating store Error updating store in subscription result handler Jan 21, 2019
@palpatim
Copy link
Contributor

@huforrest

I'm writing a test to verify this behavior, which might be fixed in #177. Can you confirm for me that the cache is empty at the time you're updating the subscription value? That is, you haven't yet processed the results of a GetConversationMessagesQuery from the server at the time you are updating the results of your subscription?

@palpatim
Copy link
Contributor

@huforrest

I've pushed a test to verify that the behavior I described above is handled by #177. If the behavior you're reporting in your original issue is different, please feel free to reopen this, but if not, I'll plan on closing this issue once we release 2.10.1 (which we're planning for later this week).

@palpatim palpatim added the pending-release Work is done, but issue can't be closed since the changes were not released yet label Feb 13, 2019
@palpatim
Copy link
Contributor

This fix is released in 2.10.1. Please let us know if you continue to see issues.

@palpatim palpatim added closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made. and removed pending-release Work is done, but issue can't be closed since the changes were not released yet labels Feb 15, 2019
@stale
Copy link

stale bot commented Feb 22, 2019

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@stale stale bot closed this as completed Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made.
Projects
None yet
Development

No branches or pull requests

4 participants