Function Fields

📣 Note: This feature is unlocked by the PHP Functions via Schema extension.

The GraphQL schema is provided with fields which expose functionalities commonly found in programming languages (such as PHP).

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:

query {
posts {
id
hasComments
notHasComments: _not(value: $__hasComments)
}
}