Skip to content

Commit

Permalink
Add builtin flag for build directives
Browse files Browse the repository at this point in the history
These have an internal implementation and should be excluded from the
DirectiveRoot. In the future this may be a func that plugins could use
to add custom implementations.
  • Loading branch information
Mathew Byrne committed Mar 6, 2019
1 parent 1968a7b commit 5ba8c8e
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
9 changes: 8 additions & 1 deletion codegen/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ func BuildData(cfg *config.Config) (*Data, error) {
return nil, err
}

dataDirectives := make(map[string]*Directive)
for name, d := range b.Directives {
if !d.Builtin {
dataDirectives[name] = d
}
}

s := Data{
Config: cfg,
Directives: b.Directives,
Directives: dataDirectives,
Schema: b.Schema,
SchemaStr: b.SchemaStr,
Interfaces: map[string]*Interface{},
Expand Down
14 changes: 9 additions & 5 deletions codegen/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

type Directive struct {
Name string
Args []*FieldArgument
Name string
Args []*FieldArgument
Builtin bool
}

func (b *builder) buildDirectives() (map[string]*Directive, error) {
Expand All @@ -22,8 +23,10 @@ func (b *builder) buildDirectives() (map[string]*Directive, error) {
if _, ok := directives[name]; ok {
return nil, errors.Errorf("directive with name %s already exists", name)
}

var builtin bool
if name == "skip" || name == "include" || name == "deprecated" {
continue
builtin = true
}

var args []*FieldArgument
Expand All @@ -50,8 +53,9 @@ func (b *builder) buildDirectives() (map[string]*Directive, error) {
}

directives[name] = &Directive{
Name: name,
Args: args,
Name: name,
Args: args,
Builtin: builtin,
}
}

Expand Down
50 changes: 50 additions & 0 deletions codegen/testserver/generated.go

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

3 changes: 3 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func (r *queryResolver) ShapeUnion(ctx context.Context) (ShapeUnion, error) {
func (r *queryResolver) Autobind(ctx context.Context) (*Autobind, error) {
panic("not implemented")
}
func (r *queryResolver) DeprecatedField(ctx context.Context) (string, error) {
panic("not implemented")
}
func (r *queryResolver) Panics(ctx context.Context) (*Panics, error) {
panic("not implemented")
}
Expand Down
1 change: 1 addition & 0 deletions codegen/testserver/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Query {
inputSlice(arg: [String!]!): Boolean!
shapeUnion: ShapeUnion!
autobind: Autobind
deprecatedField: String! @deprecated(reason: "test deprecated directive")
}

type Subscription {
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/stub.go

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

0 comments on commit 5ba8c8e

Please sign in to comment.