graphql-api-0.4.0: GraphQL API

Safe HaskellNone
LanguageHaskell2010

GraphQL

Contents

Description

Interface for GraphQL API.

Note: This module is highly subject to change. We're still figuring where to draw the lines and what to expose.

Synopsis

Running queries

interpretQuery Source #

Arguments

:: (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) 
=> Handler m api

Handler for the query. This links the query to the code you've written to handle it.

-> Text

The text of a query document. Will be parsed and then executed.

-> Maybe Name

An optional name for the operation within document to run. If Nothing, execute the only operation in the document. If Just "something", execute the query or mutation named "something".

-> VariableValues

Values for variables defined in the query document. A map of Variable to Value.

-> m Response

The outcome of running the query.

Interpet a GraphQL query.

Compiles then executes a GraphQL query.

interpretAnonymousQuery Source #

Arguments

:: (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) 
=> Handler m api

Handler for the anonymous query.

-> Text

The text of the anonymous query. Should defined only a single, unnamed query operation.

-> m Response

The result of running the query.

Interpret an anonymous GraphQL query.

Anonymous queries have no name and take no variables.

data Response Source #

GraphQL response.

A GraphQL response must:

  • be a map
  • have a "data" key iff the operation executed
  • have an "errors" key iff the operation encountered errors
  • not include "data" if operation failed before execution (e.g. syntax errors, validation errors, missing info)
  • not have keys other than "data", "errors", and "extensions"

Other interesting things:

  • Doesn't have to be JSON, but does have to have maps, strings, lists, and null
  • Can also support bool, int, enum, and float
  • Value of "extensions" must be a map

"data" must be null if an error was encountered during execution that prevented a valid response.

"errors"

  • must be a non-empty list
  • each error is a map with "message", optionally "locations" key with list of locations
  • locations are maps with 1-indexed "line" and "column" keys.

Preparing queries then running them

makeSchema :: forall api. HasObjectDefinition api => Either QueryError Schema Source #

Create a GraphQL schema.

compileQuery :: Schema -> Text -> Either QueryError (QueryDocument VariableValue) Source #

Turn some text into a valid query document.

executeQuery Source #

Arguments

:: (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) 
=> Handler m api

Handler for the query. This links the query to the code you've written to handle it.

-> QueryDocument VariableValue

A validated query document. Build one with compileQuery.

-> Maybe Name

An optional name. If Nothing, then executes the only operation in the query. If Just "something", executes the query named @"something".

-> VariableValues

Values for variables defined in the query document. A map of Variable to Value.

-> m Response

The outcome of running the query.

Execute a GraphQL query.

data QueryError Source #

Errors that can happen while processing a query document.

Instances
Eq QueryError Source # 
Instance details

Defined in GraphQL

Show QueryError Source # 
Instance details

Defined in GraphQL

GraphQLError QueryError Source # 
Instance details

Defined in GraphQL

data Schema Source #

An entire GraphQL schema.

This is very much a work in progress. Currently, the only thing we provide is a dictionary mapping type names to their definitions.

Instances
Eq Schema Source # 
Instance details

Defined in GraphQL.Internal.Schema

Methods

(==) :: Schema -> Schema -> Bool #

(/=) :: Schema -> Schema -> Bool #

Ord Schema Source # 
Instance details

Defined in GraphQL.Internal.Schema

Show Schema Source # 
Instance details

Defined in GraphQL.Internal.Schema

type VariableValues = Map Variable Value Source #

A map of variables to their values.

In GraphQL the variable values are not part of the query itself, they are instead passed in through a separate channel. Create a VariableValues from this other channel and pass it to substituteVariables.

GraphQL allows the values of variables to be specified, but doesn't provide a way for doing so in the language.

type Value = Value' ConstScalar Source #

A GraphQL value which contains no variables.