Gato GraphQL logo

Field on Field

Field on Field

Addition of the @applyField directive to the GraphQL schema, to execute a certain field on the resolved field's value.

The @applyField directive allows to execute another field, and either pass that resulting value along to another directive, or override the value of the field.

This allows us to manipulate the field's value in multiple ways, applying some functionality, and storing the new result in the response.

In the query below, the Post.title field for the object has value "Hello world!". By adding @applyField to execute field _strUpperCase:

{
  post(by: { id: 1 }) {
    title
      @passOnwards(as: "input")
      @applyField(
        name: "_strUpperCase"
        arguments: {
          text: $input
        },
        setResultInResponse: true
      )
  }
}

...the field value is transformed to upper case, producing:

{
  "data": {
    "post": {
      "title": "HELLO WORLD!"
    }
  }
}