-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Type System Extension syntax example
- Loading branch information
Showing
16 changed files
with
2,500 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,11 @@ | ||
# Type System Extension example | ||
|
||
https://facebook.github.io/graphql/draft/#sec-Type-Extensions | ||
|
||
``` | ||
$ go run ./server/server.go | ||
2018/10/25 12:46:45 connect to http://localhost:8080/ for GraphQL playground | ||
$ curl -X POST 'http://localhost:8080/query' --data-binary '{"query":"{ todos { id text state verified } }"}' | ||
{"data":{"todos":[{"id":"Todo:1","text":"Buy a cat food","state":"NOT_YET","verified":false},{"id":"Todo:2","text":"Check cat water","state":"DONE","verified":true},{"id":"Todo:3","text":"Check cat meal","state":"DONE","verified":true}]}} | ||
``` |
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,44 @@ | ||
package type_system_extension | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/99designs/gqlgen/graphql" | ||
) | ||
|
||
func EnumLogging(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) { | ||
rc := graphql.GetResolverContext(ctx) | ||
log.Printf("enum logging: %v, %s, %T, %+v", rc.Path(), rc.Field.Name, obj, obj) | ||
return next(ctx) | ||
} | ||
|
||
func FieldLogging(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) { | ||
rc := graphql.GetResolverContext(ctx) | ||
log.Printf("field logging: %v, %s, %T, %+v", rc.Path(), rc.Field.Name, obj, obj) | ||
return next(ctx) | ||
} | ||
|
||
func InputLogging(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) { | ||
rc := graphql.GetResolverContext(ctx) | ||
log.Printf("input object logging: %v, %s, %T, %+v", rc.Path(), rc.Field.Name, obj, obj) | ||
return next(ctx) | ||
} | ||
|
||
func ObjectLogging(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) { | ||
rc := graphql.GetResolverContext(ctx) | ||
log.Printf("object logging: %v, %s, %T, %+v", rc.Path(), rc.Field.Name, obj, obj) | ||
return next(ctx) | ||
} | ||
|
||
func ScalarLogging(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) { | ||
rc := graphql.GetResolverContext(ctx) | ||
log.Printf("scalar logging: %v, %s, %T, %+v", rc.Path(), rc.Field.Name, obj, obj) | ||
return next(ctx) | ||
} | ||
|
||
func UnionLogging(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) { | ||
rc := graphql.GetResolverContext(ctx) | ||
log.Printf("union logging: %v, %s, %T, %+v", rc.Path(), rc.Field.Name, obj, obj) | ||
return next(ctx) | ||
} |
Oops, something went wrong.