github.com/bewolv/gqlgen@v0.10.12/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 # You can pass a single schema file 15 schema: schema.graphql 16 17 # Or multiple files 18 schema: 19 - schema.graphql 20 - user.graphql 21 22 # Or you can use globs 23 schema: 24 - "*.graphql" 25 26 # Or globs from a root directory 27 schema: 28 - "schema/**/*.graphql" 29 30 # Let gqlgen know where to put the generated server 31 exec: 32 filename: graph/generated/generated.go 33 package: generated 34 35 # Let gqlgen know where to put the generated models (if any) 36 # Set to null to disable 37 model: 38 filename: models/generated.go 39 package: models 40 41 # Optional, turns on resolver stub generation 42 resolver: 43 filename: resolver.go # where to write them 44 type: Resolver # what's the resolver root implementation type called? 45 46 # Optional, turns on binding to field names by tag provided 47 struct_tag: json 48 49 # Optional, set to true if you prefer []Thing over []*Thing 50 omit_slice_element_pointers: false 51 52 # Optional, set to speed up generation time by not performing a final validation pass 53 skip_validation: true 54 55 # Instead of listing out every model like below, you can automatically bind to any matching types 56 # within the given path by using `model: User` or `model: models.User`. EXPERIMENTAL in v0.9.1 57 autobind: 58 - github.com/my/app/models 59 60 # Tell gqlgen about any existing models you want to reuse for 61 # graphql. These normally come from the db or a remote api. 62 models: 63 User: 64 model: models.User # can use short paths when the package is listed in autobind 65 Todo: 66 model: github.com/my/app/models.Todo # or full paths if you need to go elsewhere 67 fields: 68 id: 69 resolver: true # force a resolver to be generated 70 fieldName: todoId # bind to a different go field name 71 # model also accepts multiple backing go types. When mapping onto structs 72 # any of these types can be used, the first one is used as the default for 73 # resolver args. 74 ID: 75 model: 76 - github.com/bewolv/gqlgen/graphql.IntID 77 - github.com/bewolv/gqlgen/graphql.ID 78 ``` 79 80 Everything has defaults, so add things as you need. 81 82 ## Inline config with directives 83 84 gqlgen ships with some builtin directives that make it a little easier to manage wiring. 85 86 To start using them you first need to define them: 87 88 ```graphql 89 directive @goModel(model: String, models: [String!]) on OBJECT 90 | INPUT_OBJECT 91 | SCALAR 92 | ENUM 93 | INTERFACE 94 | UNION 95 96 directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION 97 | FIELD_DEFINITION 98 ``` 99 100 > Here be dragons 101 > 102 > gqlgen doesnt currently support user-configurable directives for SCALAR, ENUM, INTERFACE or UNION. This only works 103 > for internal directives. You can track the progress [here](https://github.com/bewolv/gqlgen/issues/760) 104 105 Now you can use these directives when defining types in your schema: 106 107 ```graphql 108 type User @goModel(model: "github.com/my/app/models.User") { 109 id: ID! @goField(name: "todoId") 110 name: String! @goField(forceResolver: true) 111 } 112 ```