diff --git a/codegen/args.go b/codegen/args.go index 905b4625eef..1d3e51aa3ad 100644 --- a/codegen/args.go +++ b/codegen/args.go @@ -30,7 +30,7 @@ type FieldArgument struct { func (f *FieldArgument) ImplDirectives() []*Directive { d := make([]*Directive, 0) for i := range f.Directives { - if !f.Directives[i].IsBuiltin() && f.Directives[i].IsLocation(ast.LocationArgumentDefinition) { + if !f.Directives[i].Builtin && f.Directives[i].IsLocation(ast.LocationArgumentDefinition) { d = append(d, f.Directives[i]) } } diff --git a/codegen/directive.go b/codegen/directive.go index 888d32e4bc1..491f92f43ac 100644 --- a/codegen/directive.go +++ b/codegen/directive.go @@ -24,11 +24,6 @@ type Directive struct { Builtin bool } -//IsBuiltin check directive -func (d *Directive) IsBuiltin() bool { - return d.Builtin || d.Name == "skip" || d.Name == "include" || d.Name == "deprecated" -} - //IsLocation check location directive func (d *Directive) IsLocation(location ...ast.DirectiveLocation) bool { for _, l := range d.Locations { @@ -127,6 +122,7 @@ func (b *builder) getDirectives(list ast.DirectiveList) ([]*Directive, error) { Name: d.Name, Args: args, DirectiveDefinition: list[i].Definition, + Builtin: b.Config.Directives[d.Name].SkipRuntime, } } diff --git a/codegen/field.go b/codegen/field.go index 8d02664daee..e51c11e3091 100644 --- a/codegen/field.go +++ b/codegen/field.go @@ -298,7 +298,7 @@ func (f *Field) ImplDirectives() []*Directive { loc = ast.LocationInputFieldDefinition } for i := range f.Directives { - if !f.Directives[i].IsBuiltin() && f.Directives[i].IsLocation(loc) { + if !f.Directives[i].Builtin && f.Directives[i].IsLocation(loc) { d = append(d, f.Directives[i]) } } diff --git a/docs/content/config.md b/docs/content/config.md index eee5cb60520..a12f406a9e5 100644 --- a/docs/content/config.md +++ b/docs/content/config.md @@ -66,3 +66,33 @@ models: Everything has defaults, so add things as you need. +## Inline config with directives + +gqlgen ships with some builtin directives that make it a little easier to manage wiring. + +To start using them you first need to define them: +```graphql +directive @goModel(model: String, models: [String!]) on OBJECT + | INPUT_OBJECT + | SCALAR + | ENUM + | INTERFACE + | UNION + +directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION + | FIELD_DEFINITION +``` + +> Here be dragons +> +> gqlgen doesnt currently support user-configurable directives for SCALAR, ENUM, INTERFACE or UNION. This only works +> for internal directives. You can track the progress [here](https://github.com/99designs/gqlgen/issues/760) + +Now you can use these directives when defining types in your schema: + +```graphql +type User @goModel(model:"github.com/my/app/models.User") { + id: ID! @goField(name:"todoId") + name: String! @goField(resolver: true) +} +```