git.sr.ht/~sircmpwn/gqlgen@v0.0.0-20200522192042-c84d29a1c940/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  
    39  # Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
    40  # struct_tag: json
    41  
    42  # Optional: turn on to use []Thing instead of []*Thing
    43  # omit_slice_element_pointers: false
    44  
    45  # Optional: set to speed up generation time by not performing a final validation pass.
    46  # skip_validation: true
    47  
    48  # gqlgen will search for any type names in the schema in these go packages
    49  # if they match it will use them, otherwise it will generate them.
    50  autobind:
    51    - "github.com/your/app/graph/model"
    52  
    53  # This section declares type mapping between the GraphQL and go type systems
    54  #
    55  # The first line in each type will be used as defaults for resolver arguments and
    56  # modelgen, the others will be allowed when binding to fields. Configure them to
    57  # your liking
    58  models:
    59    ID:
    60      model:
    61        - git.sr.ht/~sircmpwn/gqlgen/graphql.ID
    62        - git.sr.ht/~sircmpwn/gqlgen/graphql.Int
    63        - git.sr.ht/~sircmpwn/gqlgen/graphql.Int64
    64        - git.sr.ht/~sircmpwn/gqlgen/graphql.Int32
    65    Int:
    66      model:
    67        - git.sr.ht/~sircmpwn/gqlgen/graphql.Int
    68        - git.sr.ht/~sircmpwn/gqlgen/graphql.Int64
    69        - git.sr.ht/~sircmpwn/gqlgen/graphql.Int32
    70  
    71  ```
    72  
    73  Everything has defaults, so add things as you need.
    74  
    75  ## Inline config with directives
    76  
    77  gqlgen ships with some builtin directives that make it a little easier to manage wiring.
    78  
    79  To start using them you first need to define them:
    80  
    81  ```graphql
    82  directive @goModel(model: String, models: [String!]) on OBJECT
    83      | INPUT_OBJECT
    84      | SCALAR
    85      | ENUM
    86      | INTERFACE
    87      | UNION
    88  
    89  directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION
    90      | FIELD_DEFINITION
    91  ```
    92  
    93  > Here be dragons
    94  >
    95  > gqlgen doesnt currently support user-configurable directives for SCALAR, ENUM, INTERFACE or UNION. This only works
    96  > for internal directives. You can track the progress [here](https://git.sr.ht/~sircmpwn/gqlgen/issues/760)
    97  
    98  Now you can use these directives when defining types in your schema:
    99  
   100  ```graphql
   101  type User @goModel(model: "github.com/my/app/models.User") {
   102      id: ID!         @goField(name: "todoId")
   103      name: String!   @goField(forceResolver: true)
   104  }
   105  ```