Skip to main content

GraphQL

FunctionDescriptionMeta
graphql.is_valid​

output := graphql.is_valid(query, schema)

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:
query (any<string, object[any: any]>)

the GraphQL query

schema (any<string, object[any: any]>)

the GraphQL schema

Returns:
output (boolean)

true if the query is valid under the given schema. false otherwise.

v0.41.0 SDK-dependent
graphql.parse​

output := graphql.parse(query, schema)

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:
query (any<string, object[any: any]>)

the GraphQL query

schema (any<string, object[any: any]>)

the GraphQL schema

Returns:
output (array<object[any: any], object[any: any]>)

output is of the form [query_ast, schema_ast]. If the GraphQL query is valid given the provided schema, then query_ast and schema_ast are objects describing the ASTs for the query and schema.

v0.41.0 SDK-dependent
graphql.parse_and_verify​

output := graphql.parse_and_verify(query, schema)

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:
query (any<string, object[any: any]>)

the GraphQL query

schema (any<string, object[any: any]>)

the GraphQL schema

Returns:
output (array<boolean, object[any: any], object[any: any]>)

output is of the form [valid, query_ast, schema_ast]. If the query is valid given the provided schema, then valid is true, and query_ast and schema_ast are objects describing the ASTs for the GraphQL query and schema. Otherwise, valid is false and query_ast and schema_ast are {}.

v0.41.0 SDK-dependent
graphql.parse_query​

output := graphql.parse_query(query)

Returns an AST object for a GraphQL query.

Arguments:
query (string)

GraphQL query string

Returns:
output (object[any: any])

AST object for the GraphQL query.

v0.41.0 SDK-dependent
graphql.parse_schema​

output := graphql.parse_schema(schema)

Returns an AST object for a GraphQL schema.

Arguments:
schema (string)

GraphQL schema string

Returns:
output (object[any: any])

AST object for the GraphQL schema.

v0.41.0 SDK-dependent
graphql.schema_is_valid​

output := graphql.schema_is_valid(schema)

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:
schema (any<string, object[any: any]>)

the schema to verify

Returns:
output (boolean)

true if the schema is a valid GraphQL schema. false otherwise.

v0.46.0 SDK-dependent
info

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]))
}