graphql icon indicating copy to clipboard operation
graphql copied to clipboard

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

Open dmitshur opened this issue 4 years ago • 3 comments

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 avatar Sep 05 '19 01:09 dmitshur

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.

dmitshur avatar Jan 04 '20 06:01 dmitshur

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 avatar Sep 08 '21 18:09 davidkarlsen

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

davidkarlsen avatar Sep 08 '21 21:09 davidkarlsen