v0.17.40
v0.17.40 v0.17.54 v0.17.53 v0.17.52 v0.17.51 v0.17.50 v0.17.49 v0.17.48 v0.17.47 v0.17.46 v0.17.45 v0.17.44 v0.17.43 v0.17.42 v0.17.41 v0.17.39 v0.17.38 v0.17.37 v0.17.36 v0.17.35 master

Generated Model Extra Fields

Generation of additional extra fields for internal use
[edit]
You are looking at the docs for an older version (v0.17.40). The latest version is v0.17.54.

Extra fields allows you to generate additional fields for your models. These fields can be used at runtime when implementing field resolvers.

Extending your models

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.