Permalink
Browse files

Support preview GraphQL API v4 Node IDs. (#817)

Add NodeID field to objects that now expose it.

Reference: https://developer.github.com/changes/2017-12-19-graphql-node-id/.
  • Loading branch information...
anubhakushwaha authored and dmitshur committed Jan 9, 2018
1 parent 218ecc2 commit cbeb72eaf5a287299bd4eca3de3a77985370d6f5
View
@@ -30,6 +30,7 @@ type Gist struct {
GitPushURL *string `json:"git_push_url,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
NodeID *string `json:"node_id,omitempty"`
}
func (g Gist) String() string {
@@ -60,6 +61,7 @@ type GistCommit struct {
User *User `json:"user,omitempty"`
ChangeStatus *CommitStats `json:"change_status,omitempty"`
CommittedAt *Timestamp `json:"committed_at,omitempty"`
NodeID *string `json:"node_id,omitempty"`
}
func (gc GistCommit) String() string {
@@ -73,6 +75,7 @@ type GistFork struct {
ID *string `json:"id,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
NodeID *string `json:"node_id,omitempty"`
}
func (gf GistFork) String() string {
@@ -111,6 +114,9 @@ func (s *GistsService) List(ctx context.Context, user string, opt *GistListOptio
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
var gists []*Gist
resp, err := s.client.Do(ctx, req, &gists)
if err != nil {
@@ -134,6 +140,9 @@ func (s *GistsService) ListAll(ctx context.Context, opt *GistListOptions) ([]*Gi
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
var gists []*Gist
resp, err := s.client.Do(ctx, req, &gists)
if err != nil {
@@ -157,6 +166,9 @@ func (s *GistsService) ListStarred(ctx context.Context, opt *GistListOptions) ([
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
var gists []*Gist
resp, err := s.client.Do(ctx, req, &gists)
if err != nil {
@@ -175,6 +187,10 @@ func (s *GistsService) Get(ctx context.Context, id string) (*Gist, *Response, er
if err != nil {
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
gist := new(Gist)
resp, err := s.client.Do(ctx, req, gist)
if err != nil {
@@ -193,6 +209,10 @@ func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist,
if err != nil {
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
gist := new(Gist)
resp, err := s.client.Do(ctx, req, gist)
if err != nil {
@@ -211,6 +231,10 @@ func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response
if err != nil {
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
g := new(Gist)
resp, err := s.client.Do(ctx, req, g)
if err != nil {
@@ -229,6 +253,10 @@ func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist,
if err != nil {
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
g := new(Gist)
resp, err := s.client.Do(ctx, req, g)
if err != nil {
@@ -253,6 +281,9 @@ func (s *GistsService) ListCommits(ctx context.Context, id string, opt *ListOpti
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
var gistCommits []*GistCommit
resp, err := s.client.Do(ctx, req, &gistCommits)
if err != nil {
@@ -322,6 +353,9 @@ func (s *GistsService) Fork(ctx context.Context, id string) (*Gist, *Response, e
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
g := new(Gist)
resp, err := s.client.Do(ctx, req, g)
if err != nil {
@@ -341,6 +375,9 @@ func (s *GistsService) ListForks(ctx context.Context, id string) ([]*GistFork, *
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
var gistForks []*GistFork
resp, err := s.client.Do(ctx, req, &gistForks)
if err != nil {
View
@@ -23,6 +23,7 @@ func TestGistsService_List_specifiedUser(t *testing.T) {
mux.HandleFunc("/users/u/gists", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testFormValues(t, r, values{
"since": since,
})
@@ -47,6 +48,7 @@ func TestGistsService_List_authenticatedUser(t *testing.T) {
mux.HandleFunc("/gists", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
fmt.Fprint(w, `[{"id": "1"}]`)
})
@@ -77,6 +79,7 @@ func TestGistsService_ListAll(t *testing.T) {
mux.HandleFunc("/gists/public", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testFormValues(t, r, values{
"since": since,
})
@@ -103,6 +106,7 @@ func TestGistsService_ListStarred(t *testing.T) {
mux.HandleFunc("/gists/starred", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testFormValues(t, r, values{
"since": since,
})
@@ -127,6 +131,7 @@ func TestGistsService_Get(t *testing.T) {
mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
fmt.Fprint(w, `{"id": "1"}`)
})
@@ -155,6 +160,7 @@ func TestGistsService_GetRevision(t *testing.T) {
mux.HandleFunc("/gists/1/s", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
fmt.Fprint(w, `{"id": "1"}`)
})
@@ -194,6 +200,7 @@ func TestGistsService_Create(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
@@ -246,6 +253,7 @@ func TestGistsService_Edit(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
@@ -300,6 +308,7 @@ func TestGistsService_ListCommits(t *testing.T) {
mux.HandleFunc("/gists/1/commits", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testFormValues(t, r, nil)
fmt.Fprint(w, `
[
@@ -347,6 +356,7 @@ func TestGistsService_ListCommits_withOptions(t *testing.T) {
mux.HandleFunc("/gists/1/commits", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testFormValues(t, r, values{
"page": "2",
})
@@ -475,6 +485,7 @@ func TestGistsService_Fork(t *testing.T) {
mux.HandleFunc("/gists/1/forks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
fmt.Fprint(w, `{"id": "2"}`)
})
@@ -495,6 +506,7 @@ func TestGistsService_ListForks(t *testing.T) {
mux.HandleFunc("/gists/1/forks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testFormValues(t, r, nil)
fmt.Fprint(w, `
[
View
@@ -17,6 +17,7 @@ type Blob struct {
SHA *string `json:"sha,omitempty"`
Size *int `json:"size,omitempty"`
URL *string `json:"url,omitempty"`
NodeID *string `json:"node_id,omitempty"`
}
// GetBlob fetchs a blob from a repo given a SHA.
@@ -29,6 +30,9 @@ func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
blob := new(Blob)
resp, err := s.client.Do(ctx, req, blob)
return blob, resp, err
@@ -44,6 +48,9 @@ func (s *GitService) CreateBlob(ctx context.Context, owner string, repo string,
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
t := new(Blob)
resp, err := s.client.Do(ctx, req, t)
return t, resp, err
View
@@ -19,9 +19,9 @@ func TestGitService_GetBlob(t *testing.T) {
defer teardown()
mux.HandleFunc("/repos/o/r/git/blobs/s", func(w http.ResponseWriter, r *http.Request) {
if m := "GET"; m != r.Method {
t.Errorf("Request method = %v, want %v", r.Method, m)
}
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
fmt.Fprint(w, `{
"sha": "s",
"content": "blob content"
@@ -66,9 +66,8 @@ func TestGitService_CreateBlob(t *testing.T) {
v := new(Blob)
json.NewDecoder(r.Body).Decode(v)
if m := "POST"; m != r.Method {
t.Errorf("Request method = %v, want %v", r.Method, m)
}
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
want := input
if !reflect.DeepEqual(v, want) {
View
@@ -8,6 +8,7 @@ package github
import (
"context"
"fmt"
"strings"
"time"
)
@@ -31,6 +32,7 @@ type Commit struct {
HTMLURL *string `json:"html_url,omitempty"`
URL *string `json:"url,omitempty"`
Verification *SignatureVerification `json:"verification,omitempty"`
NodeID *string `json:"node_id,omitempty"`
// CommentCount is the number of GitHub comments on the commit. This
// is only populated for requests that fetch GitHub data like
@@ -67,8 +69,9 @@ func (s *GitService) GetCommit(ctx context.Context, owner string, repo string, s
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGitSigningPreview)
// TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := []string{mediaTypeGitSigningPreview, mediaTypeGraphQLNodeIDPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
c := new(Commit)
resp, err := s.client.Do(ctx, req, c)
@@ -123,6 +126,9 @@ func (s *GitService) CreateCommit(ctx context.Context, owner string, repo string
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
c := new(Commit)
resp, err := s.client.Do(ctx, req, c)
if err != nil {
@@ -11,16 +11,18 @@ import (
"fmt"
"net/http"
"reflect"
"strings"
"testing"
)
func TestGitService_GetCommit(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
acceptHeaders := []string{mediaTypeGitSigningPreview, mediaTypeGraphQLNodeIDPreview}
mux.HandleFunc("/repos/o/r/git/commits/s", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGitSigningPreview)
testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", "))
fmt.Fprint(w, `{"sha":"s","message":"m","author":{"name":"n"}}`)
})
@@ -58,6 +60,7 @@ func TestGitService_CreateCommit(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
want := &createCommit{
Message: input.Message,
Oops, something went wrong.

0 comments on commit cbeb72e

Please sign in to comment.