graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.GraphQL.Analyse

Description

Tools to analyze the structure of a GraphQL request.

Synopsis

Documentation

data Structure Source #

Overall structure of a given query. We extract the tree of fields in the output, and the graph of input variables.

data FieldInfo Source #

Information about the type of an output field; whether the base type is an object or a scalar, we store the correspoding GType to keep track of the modifiers applied to it (list or non-nullability).

data VariableInfo Source #

Information about a single variable of the query.

data InputFieldInfo Source #

Information about the type of an input field; whether the base type is an object or a scalar, we store the correspoding GType to keep track of the modifiers applied to it (list or non-nullability).

diagnoseGraphQLQuery :: SchemaIntrospection -> TypedOperationDefinition NoFragments Name -> Maybe [Text] Source #

Given the schema's definition, and a query, validate that the query is consistent. We do this by running the analysis, but discarding the result: we do not care about the structure, only about the validity of the query.

Returns Nothing if the query is valid, or a list of messages otherwise.

analyzeGraphQLQuery :: SchemaIntrospection -> TypedOperationDefinition NoFragments Name -> (Maybe Structure, [Text]) Source #

Given the schema's definition, and a query, run the analysis.

We process all possible fields, and return a partially filled structure if necessary. Given the following query:

query {
  foo {
    bar
  }
  does_not_exist {
    ghsdflgh
  }
}

We would return a structure containing:

foo: {
  bar: {
  }
}

AND an error about "does_not_exist" not existing.

In some cases, however, we might not be able to produce a structure at all, in which case we return Nothing. This either indicates that something was fundamentally wrong with the structure of the query (such as not finding an object at the top level), or that a recoverable error was not caught properly (see withCatchAndRecord).