Module

GraphQL.Type

Package
purescript-graphql
Repository
hendrikniemann/purescript-graphql

#Schema Source

data Schema :: Type -> Type -> Type

A GraphQL schema with types for context and root

#EnumType Source

data EnumType :: Type -> Type

A GraphQL enum type

Instances

#EnumValue Source

newtype EnumValue a

A type to store enum value configurations. Create new values using the enumValue function.

#ObjectType Source

data ObjectType :: Type -> Type -> Type

A GraphQL object type

Instances

#ObjectTypeField Source

data ObjectTypeField :: Type -> Type -> Type

The configuration of a field represented in native JavaScript

#ObjectTypeFieldArg Source

data ObjectTypeFieldArg :: Type -> Type

The configuration of a field argument represented in native JavaScript

Instances

#ScalarType Source

data ScalarType :: Type -> Type

A GraphQL scalar type

Instances

#ListType Source

data ListType :: Type -> Type -> Type

A GraphQL list type

Instances

#InputObjectType Source

data InputObjectType :: Type -> Type

An input object type to create complex input objects

Instances

#InputObjectTypeField Source

data InputObjectTypeField :: Type -> Type

The configuration of a field represented in native JavaScript

Instances

#GraphQLType Source

class GraphQLType a 

A type class for all GraphQL types.

Instances

#OutputType Source

class (GraphQLType a) <= OutputType a ctx 

A type class defining which types are output types and at the same time ensuring that the specific output type is bound to a certain context type.

Instances

#InputType Source

class (GraphQLType a) <= InputType a 

A type class defining which types are input types

Instances

#float Source

float :: ScalarType (Maybe Number)

The GraphQL scalar for floating point numbers.

Equivalent to JavaScript's GraphQLFloat

#id Source

id :: ScalarType (Maybe String)

The GraphQL scalar for IDs. IDs are represented and persisted as strings but can also be parsed from a number in the GraphQL document.

Equivalent to JavaScript's GraphQLID

#int Source

int :: ScalarType (Maybe Int)

The GraphQL scalar for integer values.

Equivalent to JavaScript's GraphQLInt

#string Source

string :: ScalarType (Maybe String)

The GraphQL scalar for strings.

Equivalent to JavaScript's GraphQLString

#boolean Source

boolean :: ScalarType (Maybe Boolean)

The GraphQL scalar for boolean values.

Equivalent to JavaScript's GraphQLBoolean

#list Source

list :: forall a t. GraphQLType (t a) => t a -> ListType (t a) (Maybe (Array a))

This function is used to create list types. A list type accepts an array of values and returns them as a JSON array in the response.

Equivalent to JavaScript's new GraphQLList(...)

#nonNull Source

nonNull :: forall a t. GraphQLType (t (Maybe a)) => t (Maybe a) -> t a

This function transforms any nullable type into a non-nullable type Doing so also influences the types accepted root value

nonNullableString :: ScalarType String
nonNullableString = nonNull string

Equivalent to JavaScript's new GraphQLNonNull(...)

#schema Source

schema :: forall ctx a. ObjectType ctx (Maybe a) -> Maybe (ObjectType ctx (Maybe a)) -> Schema ctx a

Create a schema given a root query object type and a root mutation type. Schemas don't need a mutation type therefore it is optional.

#enumType Source

enumType :: forall a f. Foldable f => String -> Maybe String -> f (EnumValue a) -> EnumType (Maybe a)

Create a new enum type. The enum type takes a name, an optional description and a Folable of enum values. Example:

data Status = Processing | Ready

statusType :: EnumType Status
statusType = enumType
  "Status"
  (Just "This type indicates the status of a request.")
  [ enumValue "PROCESSING" (Just "In the process.") Processing
  , enumValue "READY" (Just "Completed and ready.") Ready
  ]

#enumValue Source

enumValue :: forall a. String -> Maybe String -> a -> EnumValue a

Create a new enum value to use in an enum type definition. See enumType for an example.

#objectType Source

objectType :: forall fields ctx a. Homogeneous fields (ObjectTypeField ctx a) => String -> Maybe String -> Record fields -> ObjectType ctx (Maybe a)

Create a new object type with the following properties:

  • name is the name of the object in the schema
  • description is the description of the type
  • fields is a record of field definitions

#field Source

field :: forall args decl ctx b a t. OutputType (t b) ctx => ArgDeclarationToArgs decl args => t b -> Maybe String -> Record decl -> (a -> Record args -> ctx -> Aff b) -> ObjectTypeField ctx a

Create a field with the specified arguments using

  • type: The type of the field, must be an output type
  • description: The description of the field shown during introspection
  • args: The arguments definition that this field takes. For fields without arguments use the field' function.
  • resolve: The resolver function

The resolver function's arguments must be in a specific relationship with the args argument. This relationship is ensured by the ArgDeclarationToArgs type class.

#field' Source

field' :: forall ctx b a t. OutputType (t b) ctx => t b -> Maybe String -> (a -> ctx -> Aff b) -> ObjectTypeField ctx a

Create a simple field without arguments using

  • type the type of the field
  • description the description of the field
  • resolve a function resolving the value of the field

Examples

hello :: Field Unit Context
hello = field' string Nothing \_ _ -> pure "Hello World"

type User = { name :: String, age :: Int }
age :: Field User Context
age = field' intScalar (Just "Age of the user") resolve
  where
    resolve user _ = pure user.age

#argument Source

argument :: forall a t. InputType (t a) => t a -> Maybe String -> ObjectTypeFieldArg a

Create a single argument that can be used inside an argument declaration. Find a complete example in the documentation of the field function.

argument (nonNull string) (Just "Some description.")

#inputObjectType Source

inputObjectType :: forall r a. InputFieldsToReturnType r a => String -> Maybe String -> Record r -> InputObjectType (Maybe (Record a))

Create a new input object type. Input object types three arguments

  • name: The name of the input type that will show up to the consumer
  • description: An optional description that shows during introspection
  • fields: A homogenious record of InputObjectTypeFields

From the fields it is possible to determine the resulting type of the input using a type class contraint.

#inputField Source

inputField :: forall a t. InputType (t a) => (t a) -> (Maybe String) -> (InputObjectTypeField a)

Create a simple input field with

  • type: The type of this field
  • description: A description that will show up for this field during introspection

#ArgDeclarationToArgs Source

class ArgDeclarationToArgs (decl :: Row Type) (args :: Row Type) | decl -> args, args -> decl

A type class constraining the resolver arguments parameter to the supplied arguments declaration. E.g. if the provided args are of type { name: Argument String } the resolvers second argument needs to be of type { name: String }.

Instances

#ConvertDeclArgs Source

class ConvertDeclArgs (ldecl :: RowList) (largs :: RowList) | ldecl -> largs, largs -> ldecl

Instances

#InputFieldsToReturnType Source

class InputFieldsToReturnType (input :: Row Type) (return :: Row Type) | input -> return

Instances

#ConvertInputReturn Source

class ConvertInputReturn (linput :: RowList) (lreturn :: RowList) | linput -> lreturn

Instances