Logo
NeoArc Studio

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

PropertyRequiredDescription
idYesUnique identifier
nameYesDirective name (without @ prefix)
descriptionNoExplanation of the directive's purpose
locationsYesArray of valid GraphQL locations
argumentsNoArray of directive arguments
isRepeatableNoWhether multiple applications are allowed
isBuiltInNoMarks 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:

DirectiveLocationsPurpose
@deprecatedFIELD_DEFINITION, ARGUMENT_DEFINITION, INPUT_FIELD_DEFINITION, ENUM_VALUEMark elements as deprecated with optional reason
@skipFIELD, FRAGMENT_SPREAD, INLINE_FRAGMENTConditionally skip field during execution
@includeFIELD, FRAGMENT_SPREAD, INLINE_FRAGMENTConditionally 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:

PropertyRequiredDescription
nameYesArgument name
typeNameYesGraphQL scalar type (String, Int, Float, Boolean, ID)
nullableNoWhether the argument can be omitted
defaultValueNoDefault value if omitted
descriptionNoArgument 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"
      }
    }
  ]
}

Related Content