shurcooL / graphql

Package graphql provides a GraphQL client implementation.
MIT License
709 stars 282 forks source link

better error message or different behavior when expecting slice of structs, but have single struct #46

Open dmitshur opened 5 years ago

dmitshur commented 5 years ago

From https://github.com/shurcooL/graphql/issues/45#issuecomment-527848376:

this package should do something better in this situation. Either the error message needs to be improved, or maybe it could unmarshal just the first book and drop the rest.

See issue #45 for more context.

/cc @starjasmine

dmitshur commented 4 years ago

A related problem happened in shurcooL/githubv4#55.

The problem was that the query was Repo []struct {...} but should've been Repo struct {...}. The error was "struct field for "name" doesn't exist in any of 1 places to unmarshal".

In this case, it doesn't seem that an alternative behavior would be viable, so a more detailed and helpful error message would be better. Need to investigate whether it is viable.

davidkarlsen commented 3 years ago

Hmm, I have this query:

var query struct {
        Organization struct {
            SamlIdentityProvider struct {
                ExternalIdentities struct {
                    PageInfo struct {
                        hasNextPage githubv4.Boolean
                        endCursor   githubv4.String
                    } `graphql:"pageInfo"`
                    Edges []struct {
                        Node struct {
                            SamlIdentity struct {
                                NameId   githubv4.String
                                Username githubv4.String
                            } `graphql:"samlIdentity"`
                            User struct {
                                Login githubv4.String
                            } `graphql:"user"`
                        } `graphql:"node"`
                    } `graphql:"edges"`
                } `graphql:"externalIdentities(first: $first, after: $after)"`
            } `graphql:"samlIdentityProvider"`
        } `graphql:"organization(login: $login)"`
    }

which should match the returned structure just fine, but still it won't work?

davidkarlsen commented 3 years ago

doh, amateur-hour, I hadn't exported them. Disregard my comment.