Skip to content

Commit

Permalink
introspection for "skip" and "include" directives (fixes #30)
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Dec 6, 2016
1 parent 2e10f7b commit 232356b
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 5 deletions.
78 changes: 78 additions & 0 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,84 @@ func TestIntrospection(t *testing.T) {
}
`,
},

{
Schema: starwarsSchema,
Query: `
{
__schema {
directives {
name
description
locations
args {
name
description
type {
kind
ofType {
kind
name
}
}
}
}
}
}
`,
ExpectedResult: `
{
"__schema": {
"directives": [
{
"name": "skip",
"description": "Directs the executor to skip this field or fragment when the ` + "`" + `if` + "`" + ` argument is true.",
"locations": [
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT"
],
"args": [
{
"name": "if",
"description": "Skipped when true.",
"type": {
"kind": "NON_NULL",
"ofType": {
"kind": "SCALAR",
"name": "Boolean"
}
}
}
]
},
{
"name": "include",
"description": "Directs the executor to include this field or fragment only when the ` + "`" + `if` + "`" + ` argument is true.",
"locations": [
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT"
],
"args": [
{
"name": "if",
"description": "Included when true.",
"type": {
"kind": "NON_NULL",
"ofType": {
"kind": "SCALAR",
"name": "Boolean"
}
}
}
]
}
]
}
}
`,
},
})
}

Expand Down
39 changes: 34 additions & 5 deletions internal/exec/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,32 @@ func (r *schemaResolver) SubscriptionType() *typeResolver {
}

func (r *schemaResolver) Directives() []*directiveResolver {
return nil
return []*directiveResolver{
&directiveResolver{
name: "skip",
description: "Directs the executor to skip this field or fragment when the `if` argument is true.",
locations: []string{"FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"},
args: []*inputValueResolver{
&inputValueResolver{&common.InputValue{
Name: "if",
Desc: "Skipped when true.",
Type: &common.NonNull{OfType: booleanScalar},
}},
},
},
&directiveResolver{
name: "include",
description: "Directs the executor to include this field or fragment only when the `if` argument is true.",
locations: []string{"FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"},
args: []*inputValueResolver{
&inputValueResolver{&common.InputValue{
Name: "if",
Desc: "Included when true.",
Type: &common.NonNull{OfType: booleanScalar},
}},
},
},
}
}

type typeResolver struct {
Expand Down Expand Up @@ -458,22 +483,26 @@ func (r *enumValueResolver) DeprecationReason() *string {
}

type directiveResolver struct {
name string
description string
locations []string
args []*inputValueResolver
}

func (r *directiveResolver) Name() string {
panic("TODO")
return r.name
}

func (r *directiveResolver) Description() *string {
panic("TODO")
return &r.description
}

func (r *directiveResolver) Locations() []string {
panic("TODO")
return r.locations
}

func (r *directiveResolver) Args() []*inputValueResolver {
panic("TODO")
return r.args
}

var introspectionQuery *query.Document
Expand Down

0 comments on commit 232356b

Please sign in to comment.