Function fields are Global Fields, hence they are added to every single type in the GraphQL schema: in QueryRoot, but also in Post, User, etc.
Function fields are useful for manipulating the data once it has been retrieved, allowing us to transform a field value in whatever way it is required, and granting us powerful data import/export capabilities.
For instance, while we have a Post.hasComments fields, we may need the opposite value. Instead of creating a new field Post.notHasComments (for which we'd need to edit PHP code), we can use the Field to Input feature to input the value from hasComments into a not field, thus calculating the new value always within the GraphQL query:
The GraphQL schema is provided with directives which expose functionalities commonly found in programming languages (such as PHP).
Directive fields are useful for manipulating the data once it has been retrieved, allowing us to transform a field value in whatever way it is required, and granting us powerful data import/export capabilities.
The GraphQL schema is provided with global field _env, which allows to obtain a value from an environment variable, or from a PHP constant (most commonly defined in wp-config.php, but can also be defined elsewhere).
This query retrieves the environment constant GITHUB_ACCESS_TOKEN which we might set-up to access a private repository in GitHub:
Discover the power
Try demo now!
Play with Gato GraphQL + all extensions in your own sandbox site, for free