Skip to content

Commit

Permalink
Merge pull request #255 from 99designs/introspection-fixes
Browse files Browse the repository at this point in the history
Fix introspection api
  • Loading branch information
vektah committed Aug 4, 2018
2 parents b35804b + 7400221 commit 42f10ec
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 22 deletions.
7 changes: 5 additions & 2 deletions example/chat/generated.go

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

7 changes: 5 additions & 2 deletions example/config/generated.go

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

7 changes: 5 additions & 2 deletions example/dataloader/generated.go

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

7 changes: 5 additions & 2 deletions example/scalars/generated.go

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

7 changes: 5 additions & 2 deletions example/selection/generated.go

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

7 changes: 5 additions & 2 deletions example/starwars/generated.go

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

11 changes: 9 additions & 2 deletions example/todo/generated.go

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

4 changes: 4 additions & 0 deletions example/todo/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ type Todo {
done: Boolean!
}

"Passed to createTodo to create a new todo"
input TodoInput {
"The body text"
text: String!
"Is it done already?"
done: Boolean
}

scalar Map

"Prevents access to a field if the user doesnt have the matching role"
directive @hasRole(role: Role!) on FIELD_DEFINITION

enum Role {
Expand Down
2 changes: 1 addition & 1 deletion example/todo/todo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/99designs/gqlgen/client"
introspection "github.com/99designs/gqlgen/graphql/introspection"
"github.com/99designs/gqlgen/graphql/introspection"
"github.com/99designs/gqlgen/handler"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion graphql/introspection/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type (
InputValue struct {
Name string
Description string
DefaultValue string
DefaultValue *string
Type *Type
}
)
Expand Down
9 changes: 8 additions & 1 deletion graphql/introspection/schema.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package introspection

import "github.com/vektah/gqlparser/ast"
import (
"strings"

"github.com/vektah/gqlparser/ast"
)

type Schema struct {
schema *ast.Schema
Expand All @@ -9,6 +13,9 @@ type Schema struct {
func (s *Schema) Types() []Type {
var types []Type
for _, typ := range s.schema.Types {
if strings.HasPrefix(typ.Name, "__") {
continue
}
types = append(types, *WrapTypeFromDef(s.schema, typ))
}
return types
Expand Down
26 changes: 23 additions & 3 deletions graphql/introspection/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,20 @@ func (t *Type) Fields(includeDeprecated bool) []Field {
continue
}

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

fields = append(fields, Field{
Name: f.Name,
Description: f.Description,
Args: args,
Type: WrapTypeFromType(t.schema, f.Type),
IsDeprecated: isDeprecated(f.Directives),
DeprecationReason: deprecationReason(f.Directives),
Expand All @@ -88,14 +99,23 @@ func (t *Type) InputFields() []InputValue {
var res []InputValue
for _, f := range t.def.Fields {
res = append(res, InputValue{
Name: f.Name,
Description: f.Description,
Type: WrapTypeFromType(t.schema, f.Type),
Name: f.Name,
Description: f.Description,
Type: WrapTypeFromType(t.schema, f.Type),
DefaultValue: defaultValue(f.DefaultValue),
})
}
return res
}

func defaultValue(value *ast.Value) *string {
if value == nil {
return nil
}
val := value.String()
return &val
}

func (t *Type) Interfaces() []Type {
if t.def == nil || t.def.Kind != ast.Object {
return nil
Expand Down
7 changes: 5 additions & 2 deletions test/generated.go

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

0 comments on commit 42f10ec

Please sign in to comment.