GraphQL.Type
- Package
- purescript-graphql
- Repository
- hendrikniemann/purescript-graphql
#EnumType Source
data EnumType :: Type -> Type
A GraphQL enum type
Instances
GraphQLType (EnumType a)
OutputType (EnumType a) ctx
InputType (EnumType a)
#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
GraphQLType (ObjectType ctx a)
OutputType (ObjectType ctx a) ctx
(Fail (Above (Text "Cannot use object type with different context as field result.") (Above (Beside (Text "Expected context type: ") (Quote expected)) (Beside (Text "But received constext type: ") (Quote actual))))) => OutputType (ObjectType actual a) expected
#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
(ConvertDeclArgs ldecl largs) => ConvertDeclArgs (Cons k (ObjectTypeFieldArg a) ldecl) (Cons k a largs)
#ScalarType Source
data ScalarType :: Type -> Type
A GraphQL scalar type
Instances
GraphQLType (ScalarType a)
OutputType (ScalarType a) ctx
InputType (ScalarType a)
#ListType Source
data ListType :: Type -> Type -> Type
A GraphQL list type
Instances
GraphQLType (ListType t a)
(OutputType t ctx) => OutputType (ListType t (Maybe (Array a))) ctx
(OutputType t ctx) => OutputType (ListType t (Array a)) ctx
(InputType t) => InputType (ListType t (Array a))
(InputType t) => InputType (ListType t (Maybe (Array a)))
#InputObjectType Source
#InputObjectTypeField Source
data InputObjectTypeField :: Type -> Type
The configuration of a field represented in native JavaScript
Instances
(ConvertInputReturn linput lreturn) => ConvertInputReturn (Cons k (InputObjectTypeField a) linput) (Cons k a lreturn)
#GraphQLType Source
class GraphQLType a
A type class for all GraphQL types.
Instances
GraphQLType (ScalarType a)
GraphQLType (EnumType a)
GraphQLType (ObjectType ctx a)
GraphQLType (ListType t a)
GraphQLType (InputObjectType a)
#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
OutputType (ScalarType a) ctx
OutputType (EnumType a) ctx
OutputType (ObjectType ctx a) ctx
(Fail (Above (Text "Cannot use object type with different context as field result.") (Above (Beside (Text "Expected context type: ") (Quote expected)) (Beside (Text "But received constext type: ") (Quote actual))))) => OutputType (ObjectType actual a) expected
(OutputType t ctx) => OutputType (ListType t (Maybe (Array a))) ctx
(OutputType t ctx) => OutputType (ListType t (Array a)) ctx
#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
]
#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 schemadescription
is the description of the typefields
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 typedescription
: The description of the field shown during introspectionargs
: The arguments definition that this field takes. For fields without arguments use thefield'
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 fielddescription
the description of the fieldresolve
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 consumerdescription
: An optional description that shows during introspectionfields
: A homogenious record ofInputObjectTypeField
s
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 fielddescription
: 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
(RowToList decl ldecl, ConvertDeclArgs ldecl largs, ListToRow largs args) => ArgDeclarationToArgs decl args
#ConvertDeclArgs Source
class ConvertDeclArgs (ldecl :: RowList) (largs :: RowList) | ldecl -> largs, largs -> ldecl
Instances
ConvertDeclArgs Nil Nil
(ConvertDeclArgs ldecl largs) => ConvertDeclArgs (Cons k (ObjectTypeFieldArg a) ldecl) (Cons k a largs)
#InputFieldsToReturnType Source
class InputFieldsToReturnType (input :: Row Type) (return :: Row Type) | input -> return
Instances
(RowToList input linput, RowToList return lreturn, ConvertInputReturn linput lreturn, ListToRow linput input, ListToRow lreturn return) => InputFieldsToReturnType input return
#ConvertInputReturn Source
class ConvertInputReturn (linput :: RowList) (lreturn :: RowList) | linput -> lreturn
Instances
ConvertInputReturn Nil Nil
(ConvertInputReturn linput lreturn) => ConvertInputReturn (Cons k (InputObjectTypeField a) linput) (Cons k a lreturn)