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

How to check if the result is null? #65

Open
hug6 opened this issue May 18, 2020 · 1 comment
Open

How to check if the result is null? #65

hug6 opened this issue May 18, 2020 · 1 comment
Labels

Comments

@hug6
Copy link

hug6 commented May 18, 2020

query:

{
  repositoryOwner(login: "_dnxv__") {
    ... on ProfileOwner {
      pinnedItemsRemaining
      itemShowcase {
        hasPinnedItems
      }
    }
  }
}

result:

{
  "data": {
    "repositoryOwner": null
  }
}

but the variable query in golang is a struct, so how to check if it's null? any workaround or tricks?

@dmitshur
Copy link
Member

You can use a pointer to a struct, and check if the pointer value is nil. For example:

var q struct {
	RepositoryOwner *struct {
		ProfileOwner struct {
			PinnedItemsRemaining int
			// ...
		} `graphql:"... on ProfileOwner"`
	} `graphql:"repositoryOwner(login: \"_dnxv__\")"`
}

// call client.Query(...)

if q.RepositoryOwner == nil {
	// handle this case
}
// ...

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

No branches or pull requests

3 participants
@dmitshur @hug6 and others