GraphQL
Function | Description | Meta |
---|---|---|
graphql.is_valid |
Checks that a GraphQL query is valid against a given schema. The query and/or schema can be either GraphQL strings or AST objects from the other GraphQL builtin functions. Arguments: Returns:query (any<string, object[any: any]>)the GraphQL query schema (any<string, object[any: any]>)the GraphQL schema output (boolean)
| v0.41.0 SDK-dependent |
graphql.parse |
Returns AST objects for a given GraphQL query and schema after validating the query against the schema. Returns undefined if errors were encountered during parsing or validation. The query and/or schema can be either GraphQL strings or AST objects from the other GraphQL builtin functions. Arguments: Returns:query (any<string, object[any: any]>)the GraphQL query schema (any<string, object[any: any]>)the GraphQL schema output (array<object[any: any], object[any: any]>)
| v0.41.0 SDK-dependent |
graphql.parse_and_verify |
Returns a boolean indicating success or failure alongside the parsed ASTs for a given GraphQL query and schema after validating the query against the schema. The query and/or schema can be either GraphQL strings or AST objects from the other GraphQL builtin functions. Arguments: Returns:query (any<string, object[any: any]>)the GraphQL query schema (any<string, object[any: any]>)the GraphQL schema output (array<boolean, object[any: any], object[any: any]>)
| v0.41.0 SDK-dependent |
graphql.parse_query |
Returns an AST object for a GraphQL query. Arguments: Returns:query (string)GraphQL query string output (object[any: any])AST object for the GraphQL query. | v0.41.0 SDK-dependent |
graphql.parse_schema |
Returns an AST object for a GraphQL schema. Arguments: Returns:schema (string)GraphQL schema string output (object[any: any])AST object for the GraphQL schema. | v0.41.0 SDK-dependent |
graphql.schema_is_valid |
Checks that the input is a valid GraphQL schema. The schema can be either a GraphQL string or an AST object from the other GraphQL builtin functions. Arguments: Returns:schema (any<string, object[any: any]>)the schema to verify output (boolean)
| v0.46.0 SDK-dependent |
Custom GraphQL @directive
definitions defined by your GraphQL framework will need to be included manually as part of your GraphQL schema string in order for validation to work correctly on GraphQL queries using those directives.
Directives defined as part of the GraphQL specification (@skip
, @include
, @deprecated
, and @specifiedBy
) are supported by default, and do not need to be added to your schema manually.
GraphQL Custom @directive
Example
New @directive
definitions can be defined separately from your schema, so long as you concat
them onto the schema definition before attempting to validate a query/schema using those custom directives.
In the following example, a custom directive is defined, and then used in the schema to annotate an argument on one of the allowed query types.
package graphql_custom_directive_example
custom_directives := `
directive @customDeprecatedArgs(
reason: String
) on ARGUMENT_DEFINITION
`
schema := `
type Query {
foo(name: String! @customDeprecatedArgs(reason: "example reason")): String,
bar: String!
}
`
query := `query { foo(name: "example") }`
p {
graphql.is_valid(query, concat("", [custom_directives, schema]))
}