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

Can't access result from mutation #663

Closed
akhilpothana opened this issue Jul 23, 2019 · 6 comments
Closed

Can't access result from mutation #663

akhilpothana opened this issue Jul 23, 2019 · 6 comments
Labels
codegen Issues related to or arising from code generation

Comments

@akhilpothana
Copy link

akhilpothana commented Jul 23, 2019

I am trying to make a simple mutation to register a user. When I call .perform(mutation: GraphQLMutation), it works and a user is created in the database. I'm trying to now get information back from the server using the code below.

import Apollo

let userRegistrationInfo = RegisterMutation(email: email, name: fullName, username: username, uid: uid)
                ApolloClass.shared.client.perform(mutation: userRegistrationInfo) { result in
                    print(result?.data?.register?.id)
                }

When I only access and print result in my mutation call, this is the data I get back, so I know I'm getting something:

success(Apollo.GraphQLResult<JoinMi.RegisterMutation.Data>(data: Optional(JoinMi.RegisterMutation.Data(resultMap: ["register": Optional(["id": Optional("cjygbypjn59zt08668k7ktf6b"), "token": Optional("5jG6jbgb5dVy4ilrBLceKHCZmrS2"), "username": Optional(""), "name": Optional(""), "__typename": Optional("User")])])), errors: nil, source: Apollo.GraphQLResult<JoinMi.RegisterMutation.Data>.Source.server, dependentKeys: Optional(Set(["MUTATION_ROOT.register(email:helo@helo.com,name:,uid:5jG6jbgb5dVy4ilrBLceKHCZmrS2,username:).username", "MUTATION_ROOT.register(email:helo@helo.com,name:,uid:5jG6jbgb5dVy4ilrBLceKHCZmrS2,username:).name", "MUTATION_ROOT.register(email:helo@helo.com,name:,uid:5jG6jbgb5dVy4ilrBLceKHCZmrS2,username:).id", "MUTATION_ROOT.register(email:helo@helo.com,name:,uid:5jG6jbgb5dVy4ilrBLceKHCZmrS2,username:).__typename", "MUTATION_ROOT.register(email:helo@helo.com,name:,uid:5jG6jbgb5dVy4ilrBLceKHCZmrS2,username:)", "MUTATION_ROOT.register(email:helo@helo.com,name:,uid:5jG6jbgb5dVy4ilrBLceKHCZmrS2,username:).token"]))))

But when I try to access any of the data (e.g. result?.data?.register?.id) I get this error:

Generic parameter 'Mutation' could not be inferred

Here's my mutation:

mutation register($email: String!, $name: String, $username: String, $uid: String!) {
    register(email: $email, name: $name, username: $username, uid: $uid) {
        id
        name
        username
        token
    }
}

This is ApolloClass:

import Foundation
import Apollo

class ApolloClass {
    static let shared = ApolloClass()
    
    private(set) lazy var client = ApolloClient(url: URL(string: "...")!)
    
}

There has to be something I'm missing in the way I'm trying to access the contained data

@casey-chow
Copy link

Are you on 0.13.0? If so, see release notes:

  • SUPER-BREAKING: Updated a ton of completion closures that could use it to use Result instead of optional parameter / optional error. (Result ALL THE THINGS!!! #644). There are a few details to this one to be particularly aware of:
    • If you see a bunch of Swift build errors that are claiming Generic Parameter "Query" could not be inferred, that means you need to update your completion closure to take the single Result<Parameter, Error> parameter instead of the two (Parameter?, Error?) parameters.

@akhilpothana
Copy link
Author

akhilpothana commented Jul 23, 2019

Ugh this must be it. I was reading the notes earlier in relation to a build issue I was having and totally missed this bullet point. I will try this out. Thank you!

@designatednerd
Copy link
Contributor

@akhilpothana please let me know if this worked!

@designatednerd designatednerd added the codegen Issues related to or arising from code generation label Jul 24, 2019
@designatednerd
Copy link
Contributor

Given that this is covered in the release notes for 0.13.0, I'm gonna close this one out. Please reopen if you're still having problems!

@akhilpothana
Copy link
Author

@designatednerd sorry! yes that was the issue. All fixed!

@designatednerd
Copy link
Contributor

Awesome, thanks for letting us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Issues related to or arising from code generation
Projects
None yet
Development

No branches or pull requests

3 participants