Skip to content

Commit

Permalink
Merge branch 'introspection-directive-args' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Aug 23, 2018
2 parents b8695fb + 12efa2d commit 15d8d4a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
36 changes: 27 additions & 9 deletions graphql/introspection/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,34 @@ func (s *Schema) SubscriptionType() *Type {

func (s *Schema) Directives() []Directive {
var res []Directive

for _, d := range s.schema.Directives {
var locs []string
for _, loc := range d.Locations {
locs = append(locs, string(loc))
}
res = append(res, Directive{
Name: d.Name,
Description: d.Description,
Locations: locs,
})
res = append(res, s.directiveFromDef(d))
}

return res
}

func (s *Schema) directiveFromDef(d *ast.DirectiveDefinition) Directive {
var locs []string
for _, loc := range d.Locations {
locs = append(locs, string(loc))
}

var args []InputValue
for _, arg := range d.Arguments {
args = append(args, InputValue{
Name: arg.Name,
Description: arg.Description,
DefaultValue: defaultValue(arg.DefaultValue),
Type: WrapTypeFromType(s.schema, arg.Type),
})
}

return Directive{
Name: d.Name,
Description: d.Description,
Locations: locs,
Args: args,
}
}
39 changes: 36 additions & 3 deletions integration/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions integration/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import {ApolloClient} from "apollo-client";
import fetch from "node-fetch";
import gql from 'graphql-tag';

if (!process.env.SERVER_URL) {
throw "SERVER_URL must be set"
}
var uri = process.env.SERVER_URL || 'http://localhost:8080/query';

const client = new ApolloClient({
link: new HttpLink({uri: process.env.SERVER_URL, fetch: fetch}),
link: new HttpLink({uri, fetch}),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
Expand Down
5 changes: 4 additions & 1 deletion integration/schema-expected.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# source: http://localhost:8080/query
# timestamp: Fri Aug 10 2018 11:50:28 GMT+1000 (AEST)
# timestamp: Thu Aug 23 2018 10:30:37 GMT+1000 (AEST)

"""This directive does magical things"""
directive @magic(kind: Int) on FIELD_DEFINITION

enum DATE_FILTER_OP {
EQ
Expand Down
3 changes: 3 additions & 0 deletions integration/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"This directive does magical things"
directive @magic(kind: Int) on FIELD_DEFINITION

type Element {
child: Element!
error: Boolean!
Expand Down

0 comments on commit 15d8d4a

Please sign in to comment.