Directives
Define custom directives with all standard GraphQL locations, arguments, and repeatable support.
Directives provide a way to annotate GraphQL schema elements with additional metadata. NeoArc Studio supports all standard GraphQL directive locations, allowing you to define and document custom directives for authentication, caching, validation, and more.
Directive Properties
| Property | Required | Description |
|---|---|---|
| id | Yes | Unique identifier |
| name | Yes | Directive name (without @ prefix) |
| description | No | Explanation of the directive's purpose |
| locations | Yes | Array of valid GraphQL locations |
| arguments | No | Array of directive arguments |
| isRepeatable | No | Whether multiple applications are allowed |
| isBuiltIn | No | Marks built-in directives like @deprecated |
Directive Locations
GraphQL defines locations across two categories where directives can be applied:
Built-in Directives
GraphQL provides three built-in directives:
| Directive | Locations | Purpose |
|---|---|---|
| @deprecated | FIELD_DEFINITION, ARGUMENT_DEFINITION, INPUT_FIELD_DEFINITION, ENUM_VALUE | Mark elements as deprecated with optional reason |
| @skip | FIELD, FRAGMENT_SPREAD, INLINE_FRAGMENT | Conditionally skip field during execution |
| @include | FIELD, FRAGMENT_SPREAD, INLINE_FRAGMENT | Conditionally include field during execution |
{
"id": "directive-deprecated",
"name": "deprecated",
"description": "Marks an element as deprecated with optional reason and migration guidance.",
"locations": [
"FIELD_DEFINITION",
"ARGUMENT_DEFINITION",
"INPUT_FIELD_DEFINITION",
"ENUM_VALUE"
],
"arguments": [
{
"name": "reason",
"typeName": "String",
"nullable": true,
"defaultValue": "No longer supported",
"description": "Deprecation reason and migration guidance"
}
],
"isRepeatable": false,
"isBuiltIn": true
}
Custom Directive Examples
Directive Arguments
Directive arguments allow configuration when the directive is applied:
| Property | Required | Description |
|---|---|---|
| name | Yes | Argument name |
| typeName | Yes | GraphQL scalar type (String, Int, Float, Boolean, ID) |
| nullable | No | Whether the argument can be omitted |
| defaultValue | No | Default value if omitted |
| description | No | Argument explanation |
Repeatable Directives
Set isRepeatable: true when a directive can be applied multiple times to the same element:
{
"id": "directive-tag",
"name": "tag",
"description": "Adds a categorisation tag to a field or type.",
"locations": ["FIELD_DEFINITION", "OBJECT"],
"arguments": [
{
"name": "name",
"typeName": "String",
"nullable": false
}
],
"isRepeatable": true
}
Repeatable example in SDL:
type Product @tag(name: "commerce") @tag(name: "catalogue") {
id: ID!
}Applying Directives
Directives defined in the API can be applied to:
- Operations - Via the operation's directives property
- Arguments - Via individual argument directive arrays
- Interfaces - Via interface and interface field directive arrays
{
"name": "email",
"typeName": "String",
"nullable": false,
"directives": [
{
"directiveId": "directive-sensitive",
"arguments": {
"reason": "Contains user email address"
}
}
]
}