Skip to content

Commit

Permalink
add Type System Extension syntax example
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Oct 25, 2018
1 parent ab4752c commit d723844
Show file tree
Hide file tree
Showing 16 changed files with 2,500 additions and 0 deletions.
11 changes: 11 additions & 0 deletions example/type-system-extension/README.md
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}]}}
```
44 changes: 44 additions & 0 deletions example/type-system-extension/directive.go
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)
}
Loading

0 comments on commit d723844

Please sign in to comment.