# Source: https://docs.hypermode.com/dgraph/graphql/schema/directives/generate.md

# @generate

> The @generate directive specifies which GraphQL APIs are generated for a given type. Without it, all queries & mutations are generated except subscription.

<Info>
  We're overhauling Dgraph's docs to make them clearer and more approachable. If
  you notice any issues during this transition or have suggestions, please
  [let us know](https://github.com/hypermodeinc/docs/issues).
</Info>

The `@generate` directive is used to specify which GraphQL APIs are generated
for a given type.

Here's the GraphQL definition of the directive

```graphql
input GenerateQueryParams {
  get: Boolean
  query: Boolean
  password: Boolean
  aggregate: Boolean
}

input GenerateMutationParams {
  add: Boolean
  update: Boolean
  delete: Boolean
}
directive @generate(
  query: GenerateQueryParams
  mutation: GenerateMutationParams
  subscription: Boolean
) on OBJECT | INTERFACE
```

The corresponding APIs are generated by setting the `Boolean` variables inside
the `@generate` directive to `true`. Passing `false` forbids the generation of
the corresponding APIs.

The default value of the `subscription` variable is `false` while the default
value of all other variables is `true`. Therefore, if no `@generate` directive
is specified for a type, all queries and mutations except `subscription` are
generated.

## Example of @generate directive

```graphql
type Person
  @generate(
    query: { get: false, query: true, aggregate: false }
    mutation: { add: true, delete: false }
    subscription: false
  ) {
  id: ID!
  name: String!
}
```

The GraphQL schema above will generate a `queryPerson` query and `addPerson`,
`updatePerson` mutations. It won't generate `getPerson`, `aggregatePerson`
queries nor a `deletePerson` mutation as these have been marked as `false` using
the `@generate` directive. Note that the `updatePerson` mutation is generated
because the default value of the `update` variable is `true`.