github.com/mstephano/gqlgen-schemagen@v0.0.0-20230113041936-dd2cd4ea46aa/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 layout: follow-schema 21 dir: graph/generated 22 package: generated 23 24 # Enable Apollo federation support 25 federation: 26 filename: graph/federation.go 27 package: graph 28 29 # Where should any generated models go? 30 model: 31 filename: graph/model/models_gen.go 32 package: model 33 34 # Where should the resolver implementations go? 35 resolver: 36 layout: follow-schema 37 dir: graph 38 package: graph 39 filename_template: "{name}.resolvers.go" 40 41 # Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models 42 # struct_tag: json 43 44 # Optional: turn on to use []Thing instead of []*Thing 45 # omit_slice_element_pointers: false 46 47 # Optional: turn off to make struct-type struct fields not use pointers 48 # e.g. type Thing struct { FieldA OtherThing } instead of { FieldA *OtherThing } 49 # struct_fields_always_pointers: true 50 51 # Optional: turn off to make resolvers return values instead of pointers for structs 52 # resolvers_always_return_pointers: true 53 54 # Optional: turn on to return pointers instead of values in unmarshalInput 55 # return_pointers_in_unmarshalinput: false 56 57 # Optional: set to speed up generation time by not performing a final validation pass. 58 # skip_validation: true 59 60 # Optional: set to skip running `go mod tidy` when generating server code 61 # skip_mod_tidy: true 62 63 # gqlgen will search for any type names in the schema in these go packages 64 # if they match it will use them, otherwise it will generate them. 65 # autobind: 66 # - "github.com/[YOUR_APP_DIR]/graph/model" 67 68 # This section declares type mapping between the GraphQL and go type systems 69 # 70 # The first line in each type will be used as defaults for resolver arguments and 71 # modelgen, the others will be allowed when binding to fields. Configure them to 72 # your liking 73 models: 74 ID: 75 model: 76 - github.com/mstephano/gqlgen-schemagen/graphql.ID 77 - github.com/mstephano/gqlgen-schemagen/graphql.Int 78 - github.com/mstephano/gqlgen-schemagen/graphql.Int64 79 - github.com/mstephano/gqlgen-schemagen/graphql.Int32 80 Int: 81 model: 82 - github.com/mstephano/gqlgen-schemagen/graphql.Int 83 - github.com/mstephano/gqlgen-schemagen/graphql.Int64 84 - github.com/mstephano/gqlgen-schemagen/graphql.Int32 85 ``` 86 87 Everything has defaults, so add things as you need. 88 89 ## Inline config with directives 90 91 gqlgen ships with some builtin directives that make it a little easier to manage wiring. 92 93 To start using them you first need to define them: 94 95 ```graphql 96 directive @goModel( 97 model: String 98 models: [String!] 99 ) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION 100 101 directive @goField( 102 forceResolver: Boolean 103 name: String 104 ) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION 105 106 directive @goTag(key: String!, value: String) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION 107 ``` 108 109 > Here be dragons 110 > 111 > gqlgen doesnt currently support user-configurable directives for SCALAR, ENUM, INTERFACE or UNION. This only works 112 > for internal directives. You can track the progress [here](https://github.com/mstephano/gqlgen-schemagen/issues/760) 113 114 Now you can use these directives when defining types in your schema: 115 116 ```graphql 117 type User @goModel(model: "github.com/my/app/models.User") { 118 id: ID! @goField(name: "todoId") 119 name: String! @goField(forceResolver: true) @goTag(key: "xorm", value: "-") @goTag(key: "yaml") 120 } 121 ``` 122 123 The builtin directives `goField`, `goModel` and `goTag` are automatically registered to `skip_runtime`. Any directives registered as `skip_runtime` will not exposed during introspection and are used during code generation only. 124 125 If you have created a new code generation plugin using a directive which does not require runtime execution, the directive will need to be set to `skip_runtime`. 126 127 e.g. a custom directive called `constraint` would be set as `skip_runtime` using the following configuration 128 129 ```yml 130 # custom directives which are not exposed during introspection. These directives are 131 # used for code generation only 132 directives: 133 constraint: 134 skip_runtime: true 135 ```