-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from sonatard/add-example
Add examples
- Loading branch information
Showing
13 changed files
with
409 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
schema: | ||
- ./schema/schema.graphql | ||
model: | ||
filename: ./model/models_gen.go | ||
autobind: | ||
- github.com/Yamashou/gqlgenc/example/autobind/model | ||
client: | ||
filename: ./gen/client.go | ||
models: | ||
DateTime: | ||
model: github.com/99designs/gqlgen/graphql.Time | ||
query: | ||
- "./query/*.graphql" | ||
generate: | ||
clientV2: true | ||
clientInterfaceName: "GithubGraphQLClient" | ||
query: false | ||
mutation: false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/Yamashou/gqlgenc/client" | ||
"github.com/Yamashou/gqlgenc/clientv2" | ||
"github.com/Yamashou/gqlgenc/example/github/gen" | ||
) | ||
|
||
func main() { | ||
// This example only read public repository. You don't need to select scopes. | ||
token := os.Getenv("GITHUB_TOKEN") | ||
ctx := context.Background() | ||
|
||
githubClient := &gen.Client{ | ||
Client: clientv2.NewClient(http.DefaultClient, "https://api.github.com/graphql", nil, | ||
func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res interface{}, next clientv2.RequestInterceptorFunc) error { | ||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) | ||
|
||
return next(ctx, req, gqlInfo, res) | ||
}), | ||
} | ||
getUser, err := githubClient.GetUser(ctx, 10, 10) | ||
if err != nil { | ||
if handledError, ok := err.(*client.ErrorResponse); ok { | ||
fmt.Fprintf(os.Stderr, "handled error: %s\n", handledError.Error()) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "unhandled error: %s\n", err.Error()) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(*getUser.Viewer.Name, getUser.Viewer.Repositories.Nodes[0].Name) | ||
for _, repository := range getUser.Viewer.Repositories.Nodes { | ||
fmt.Println(repository.Name) | ||
for _, language := range repository.Languages.Nodes { | ||
fmt.Println(language.Name) | ||
} | ||
|
||
res, err := githubClient.GetNode(ctx, repository.ID) | ||
if err != nil { | ||
if handledError, ok := err.(*client.ErrorResponse); ok { | ||
fmt.Fprintf(os.Stderr, "handled error: %s\n", handledError.Error()) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "unhandled error: %s\n", err.Error()) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(res.Node.ID, res.Node.Repository.Name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package model | ||
|
||
type Profile struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query GetUserProfileName { | ||
user { | ||
profile { | ||
name | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
schema { | ||
query: Query | ||
mutation: Mutation | ||
} | ||
|
||
type Query { | ||
user: User! | ||
} | ||
|
||
type Mutation { | ||
dummy: String! | ||
} | ||
|
||
type User { | ||
id: ID! | ||
profile: Profile! | ||
} | ||
|
||
type Profile { | ||
id: ID! | ||
name: String! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
schema: | ||
- ./schema/schema.graphql | ||
model: | ||
filename: ./model/models_gen.go | ||
client: | ||
filename: ./gen/client.go | ||
models: | ||
DateTime: | ||
model: github.com/99designs/gqlgen/graphql.Time | ||
query: | ||
- "./query/*.graphql" | ||
generate: | ||
clientV2: true | ||
clientInterfaceName: "GithubGraphQLClient" | ||
query: false | ||
mutation: false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/Yamashou/gqlgenc/client" | ||
"github.com/Yamashou/gqlgenc/clientv2" | ||
"github.com/Yamashou/gqlgenc/example/github/gen" | ||
) | ||
|
||
func main() { | ||
// This example only read public repository. You don't need to select scopes. | ||
token := os.Getenv("GITHUB_TOKEN") | ||
ctx := context.Background() | ||
|
||
githubClient := &gen.Client{ | ||
Client: clientv2.NewClient(http.DefaultClient, "https://api.github.com/graphql", nil, | ||
func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res interface{}, next clientv2.RequestInterceptorFunc) error { | ||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) | ||
|
||
return next(ctx, req, gqlInfo, res) | ||
}), | ||
} | ||
getUser, err := githubClient.GetUser(ctx, 10, 10) | ||
if err != nil { | ||
if handledError, ok := err.(*client.ErrorResponse); ok { | ||
fmt.Fprintf(os.Stderr, "handled error: %s\n", handledError.Error()) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "unhandled error: %s\n", err.Error()) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(*getUser.Viewer.Name, getUser.Viewer.Repositories.Nodes[0].Name) | ||
for _, repository := range getUser.Viewer.Repositories.Nodes { | ||
fmt.Println(repository.Name) | ||
for _, language := range repository.Languages.Nodes { | ||
fmt.Println(language.Name) | ||
} | ||
|
||
res, err := githubClient.GetNode(ctx, repository.ID) | ||
if err != nil { | ||
if handledError, ok := err.(*client.ErrorResponse); ok { | ||
fmt.Fprintf(os.Stderr, "handled error: %s\n", handledError.Error()) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "unhandled error: %s\n", err.Error()) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(res.Node.ID, res.Node.Repository.Name) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query GetUserProfileName { | ||
user { | ||
profile { | ||
name | ||
} | ||
} | ||
} |
Oops, something went wrong.