Generated Model Extra Fields
Generation of additional extra fields for internal use
[edit]
Extra fields allows you to generate additional fields for your models. These fields can be used at runtime when implementing field resolvers.
Imagine you have a model named User and you want to extend a generated struct with additional data used in your service.
The schema is:
type User {
id: ID!
name: String!
}
Extra fields can be defined in gqlgen.yaml configuration:
models:
User:
extraFields:
Session:
description: "A Session used by this user"
type: "github.com/author/mypkg.Session"
The generated code would look like:
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
type User struct {
ID string
Name string
// A Session used by this user.
Session mypkg.Session
}
After these steps you have an extra field for your server implementation and the field is not being exposed to a caller.