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 encode GraphQL Aliases #39

Closed
davidoram opened this Issue Nov 11, 2018 · 2 comments

Comments

2 participants
@davidoram

davidoram commented Nov 11, 2018

Hi, I'm trying to figure out how to encode GraphQL aliases (https://graphql.github.io/learn/queries/#aliases) using this library.

I'm trying to encode something like this query:

{
  repository(owner: "davidoram", name: "gittest") {
    nameWithOwner
    tags: refs(refPrefix: "refs/tags/", last: 30, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
      edges {
        tag: node {
          name
          target {
            sha: oid
          }
        }
      }
    }
  }
}

.. in particular I haven't figured out how to encode the tags: refs alias as a go struct with the appropriate graphql struct tag?

@dmitshur

This comment has been minimized.

Member

dmitshur commented Nov 11, 2018

@davidoram Thanks for asking. Aliases are supported, but I haven't documented them yet (see #22). I hope to fix that soon.

The answer is as follows. A GraphQL query like this:

query {
  aliasGoesHere: repository(owner: "golang", name: "go") {
    nameWithOwner
    description
  }
}

Would be implemented with the following Go query struct:

var query struct {
	AliasGoesHere struct {
		NameWithOwner string
		Description   string
	} `graphql:"aliasGoesHere: repository(owner: \"golang\", name: \"go\")"`
}

Basically, you just put the alias prefix at the beginning of the graphql tag. Let me know if that makes sense.

@davidoram

This comment has been minimized.

davidoram commented Nov 11, 2018

Thanks @dmitshur, that worked like a charm 👍 .

If it helps anyone else - I have another example here where I retrieve the tags for a repository

@davidoram davidoram closed this Nov 11, 2018

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