directive @value

The @value directive defines a value that can be applied in various contexts, each with specific behaviors.

  • When applied to a field, selecting the field will return the specified value.

If no arguments are provided (@value) then the value is null.

Arguments

const: JSON

This argument sets the element to a constant value. The value must be assignable or convertible to the element's type.

script: StepZen_Script

This argument sets the element to the result of the expression defined in the script.

The script has access to the arguments of the annotated field and any JWT claims using $jwt. The type of the expression should be convertible to the annotated element's type.

If the annotated element's type is an abstract type then the expression must include setting __typename to indicate the object type of each returned instance.

Locations

Type System: FIELD_DEFINITION

Examples

Script (JSONata) field

type Query {
  sum(a: Int!, b: Int!): Int! @value(script: {src: "a+b", language: JSONATA})
}

Script (ECMAScript) field

type Query {
  customer(id: Int!, name: String): Customer!
    @value(
      script: {
        src: """
        Object({id:id, name:name})
        """
        language: ECMASCRIPT
      }
    )
}

language argument defaults to ECMASCRIPT so it can be omitted.

Constant field

type Query {
  pi:Float! @value(const:3.14159)
}

Null field

Field Employee.xid will always resolve to null.

type Employee {
  id:ID!
  name:String!
  xid:ID @value
}

This can be useful when an object type corresponding to a backend cannot supply a value for an interface type.