github.com/animeshon/gqlgen@v0.13.1-0.20210304133704-3a770431bb6d/docs/content/config.md (about) 1 --- 2 linkTitle: Configuration 3 title: How to configure gqlgen using gqlgen.yml 4 description: How to configure gqlgen using gqlgen.yml 5 menu: main 6 weight: -5 7 --- 8 9 gqlgen can be configured using a `gqlgen.yml` file, by default it will be loaded from the current directory, or any parent directory. 10 11 Example: 12 13 ```yml 14 # Where are all the schema files located? globs are supported eg src/**/*.graphqls 15 schema: 16 - graph/*.graphqls 17 18 # Where should the generated server code go? 19 exec: 20 filename: graph/generated/generated.go 21 package: generated 22 23 # Enable Apollo federation support 24 federation: 25 filename: graph/generated/federation.go 26 package: generated 27 28 # Where should any generated models go? 29 model: 30 filename: graph/model/models_gen.go 31 package: model 32 33 # Where should the resolver implementations go? 34 resolver: 35 layout: follow-schema 36 dir: graph 37 package: graph 38 filename_template: "{name}.resolvers.go" 39 40 # Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models 41 # struct_tag: json 42 43 # Optional: turn on to use []Thing instead of []*Thing 44 # omit_slice_element_pointers: false 45 46 # Optional: set to speed up generation time by not performing a final validation pass. 47 # skip_validation: true 48 49 # gqlgen will search for any type names in the schema in these go packages 50 # if they match it will use them, otherwise it will generate them. 51 autobind: 52 - "github.com/your/app/graph/model" 53 54 # This section declares type mapping between the GraphQL and go type systems 55 # 56 # The first line in each type will be used as defaults for resolver arguments and 57 # modelgen, the others will be allowed when binding to fields. Configure them to 58 # your liking 59 models: 60 ID: 61 model: 62 - github.com/99designs/gqlgen/graphql.ID 63 - github.com/99designs/gqlgen/graphql.Int 64 - github.com/99designs/gqlgen/graphql.Int64 65 - github.com/99designs/gqlgen/graphql.Int32 66 Int: 67 model: 68 - github.com/99designs/gqlgen/graphql.Int 69 - github.com/99designs/gqlgen/graphql.Int64 70 - github.com/99designs/gqlgen/graphql.Int32 71 72 ``` 73 74 Everything has defaults, so add things as you need. 75 76 ## Inline config with directives 77 78 gqlgen ships with some builtin directives that make it a little easier to manage wiring. 79 80 To start using them you first need to define them: 81 82 ```graphql 83 directive @goModel(model: String, models: [String!]) on OBJECT 84 | INPUT_OBJECT 85 | SCALAR 86 | ENUM 87 | INTERFACE 88 | UNION 89 90 directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION 91 | FIELD_DEFINITION 92 ``` 93 94 > Here be dragons 95 > 96 > gqlgen doesnt currently support user-configurable directives for SCALAR, ENUM, INTERFACE or UNION. This only works 97 > for internal directives. You can track the progress [here](https://github.com/99designs/gqlgen/issues/760) 98 99 Now you can use these directives when defining types in your schema: 100 101 ```graphql 102 type User @goModel(model: "github.com/my/app/models.User") { 103 id: ID! @goField(name: "todoId") 104 name: String! @goField(forceResolver: true) 105 } 106 ```