镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

How to check if the result is null? #65

Open

Description

@hug6

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?

Activity

  1. dmitshur commented on May 18, 2020

    @dmitshur
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions