github.com/operandinc/gqlgen@v0.16.1/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/generated/federation.go
    27    package: generated
    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: set to speed up generation time by not performing a final validation pass.
    48  # skip_validation: true
    49  
    50  # Optional: set to skip running `go mod tidy` when generating server code
    51  # skip_mod_tidy: true
    52  
    53  # gqlgen will search for any type names in the schema in these go packages
    54  # if they match it will use them, otherwise it will generate them.
    55  # autobind:
    56  #   - "github.com/[YOUR_APP_DIR]/graph/model"
    57  
    58  # This section declares type mapping between the GraphQL and go type systems
    59  #
    60  # The first line in each type will be used as defaults for resolver arguments and
    61  # modelgen, the others will be allowed when binding to fields. Configure them to
    62  # your liking
    63  models:
    64    ID:
    65      model:
    66        - github.com/operandinc/gqlgen/graphql.ID
    67        - github.com/operandinc/gqlgen/graphql.Int
    68        - github.com/operandinc/gqlgen/graphql.Int64
    69        - github.com/operandinc/gqlgen/graphql.Int32
    70    Int:
    71      model:
    72        - github.com/operandinc/gqlgen/graphql.Int
    73        - github.com/operandinc/gqlgen/graphql.Int64
    74        - github.com/operandinc/gqlgen/graphql.Int32
    75  ```
    76  
    77  Everything has defaults, so add things as you need.
    78  
    79  ## Inline config with directives
    80  
    81  gqlgen ships with some builtin directives that make it a little easier to manage wiring.
    82  
    83  To start using them you first need to define them:
    84  
    85  ```graphql
    86  directive @goModel(
    87  	model: String
    88  	models: [String!]
    89  ) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION
    90  
    91  directive @goField(
    92  	forceResolver: Boolean
    93  	name: String
    94  ) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION
    95  
    96  directive @goTag(
    97  	key: String!
    98  	value: String
    99  ) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION
   100  ```
   101  
   102  > Here be dragons
   103  >
   104  > gqlgen doesnt currently support user-configurable directives for SCALAR, ENUM, INTERFACE or UNION. This only works
   105  > for internal directives. You can track the progress [here](https://github.com/operandinc/gqlgen/issues/760)
   106  
   107  Now you can use these directives when defining types in your schema:
   108  
   109  ```graphql
   110  type User @goModel(model: "github.com/my/app/models.User") {
   111  	id: ID! @goField(name: "todoId")
   112  	name: String!
   113  		@goField(forceResolver: true)
   114  		@goTag(key: "xorm", value: "-")
   115  		@goTag(key: "yaml")
   116  }
   117  ```
   118  
   119  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.
   120  
   121  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`.
   122  
   123  e.g. a custom directive called `constraint` would be set as `skip_runtime` using the following configuration
   124  
   125  ```yml
   126  # custom directives which are not exposed during introspection. These directives are
   127  # used for code generation only
   128  directives:
   129    constraint:
   130      skip_runtime: true
   131  ```