Permalink
Browse files

Refactored to use GraphQL aliases - see shurcooL/githubv4#39 (comment)

  • Loading branch information...
davidoram committed Nov 11, 2018
1 parent d4f3cd3 commit 71e986f52b169375e8c4310ed2c24b30996514da
Showing with 6 additions and 6 deletions.
  1. +6 −6 main.go
12 main.go
@@ -116,16 +116,16 @@ type QueryRepoDetail struct {
Releases struct {
Nodes []Release
} `graphql:"releases(first: $maxReleases, orderBy: {field: CREATED_AT, direction: DESC})"`
Refs struct {
Tags struct {
Edges []struct {

This comment has been minimized.

@dmitshur

dmitshur Nov 12, 2018

In case it's helpful, you can probably simplify this further. Instead of using edges and then accessing the node inside, you could access the list of nodes directly via nodes. See the second field at https://developer.github.com/v4/object/refconnection/.

This comment has been minimized.

@davidoram

davidoram Nov 12, 2018

Owner

Thanks @dmitshur - I'll refactor that in my next release

Node struct {
Tag struct {
Name githubv4.String
Target struct {
Oid githubv4.String
}
}
} `graphql:"tag: node()"`

This comment has been minimized.

@dmitshur

dmitshur Nov 12, 2018

You can omit the empty brackets if you want, e.g., just graphql:"tag: node".

This comment has been minimized.

@davidoram
}
} `graphql:"refs(refPrefix: $tagPrefix, last: $maxTags, orderBy: {field: TAG_COMMIT_DATE, direction: ASC})"`
} `graphql:"tags: refs(refPrefix: $tagPrefix, last: $maxTags, orderBy: {field: TAG_COMMIT_DATE, direction: ASC})"`
} `graphql:"repository(owner: $owner, name: $name)"`
}
@@ -355,11 +355,11 @@ Usage:
log.Printf("\nTags:\n-----\n")
tmpl = "%-70s %s\n"
log.Printf(tmpl, "Tag", "Sha")
for i, t := range q.Repository.Refs.Edges {
for i, t := range q.Repository.Tags.Edges {
if i >= maxTags {
break
}
log.Printf(tmpl, t.Node.Name, t.Node.Target.Oid)
log.Printf(tmpl, t.Tag.Name, t.Tag.Target.Oid)
}
return nil
}

0 comments on commit 71e986f

Please sign in to comment.