github.com/99designs/gqlgen@v0.17.45/docs/content/recipes/extra_fields.md (about)

     1  ---
     2  title: "Generation of additional extra fields for internal use"
     3  description: Pass implementation specific fields to the children resolvers without being forced to define your own types for a GraphQL model.
     4  linkTitle: Generated Model Extra Fields
     5  menu: { main: { parent: 'recipes' } }
     6  ---
     7  
     8  Extra fields allows you to generate additional fields for your models.
     9  These fields can be used at runtime when implementing field resolvers.
    10  
    11  ## Extending your models
    12  Imagine you have a model named User and you want to extend a generated struct with additional data used in your service.
    13  
    14  The schema is:
    15  
    16  ```graphql
    17  type User {
    18    id: ID!
    19    name: String!
    20  }
    21  ```
    22  
    23  Extra fields can be defined in gqlgen.yaml configuration:
    24  
    25  ```yaml
    26  models:
    27    User:
    28      extraFields:
    29        Session:
    30          description: "A Session used by this user"
    31          type: "github.com/author/mypkg.Session"
    32  ```
    33  
    34  The generated code would look like:
    35  
    36  ```go
    37  // Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
    38  
    39  type User struct {
    40  	ID   string
    41  	Name string
    42  	// A Session used by this user.
    43  	Session mypkg.Session
    44  }
    45  ```
    46  
    47  After these steps you have an extra field for your server implementation and the field is not being exposed to a caller.