v0.17.44
v0.17.44 v0.17.43 v0.17.42 v0.17.41 v0.17.40 v0.17.39 v0.17.38 v0.17.37 v0.17.36 v0.17.35 v0.17.34 v0.17.33 v0.17.32 v0.17.31 v0.17.30 v0.17.29 v0.17.28 v0.17.27 v0.17.26 v0.17.25 master

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.

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.