Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jun 26, 2019
1 parent 64aca61 commit c14f865
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion codegen/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Expand Down
6 changes: 1 addition & 5 deletions codegen/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}

}
Expand Down
2 changes: 1 addition & 1 deletion codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Expand Down
30 changes: 30 additions & 0 deletions docs/content/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

0 comments on commit c14f865

Please sign in to comment.