2016-03-09 01:15:46 +01:00
|
|
|
|
{- | This module defines an
|
|
|
|
|
abstract syntax tree for the GraphQL language, based on
|
|
|
|
|
<https://facebook.github.io/graphql/ Facebook's GraphQL Specification>.
|
|
|
|
|
-}
|
|
|
|
|
|
2015-09-12 15:16:28 +02:00
|
|
|
|
module Data.GraphQL.AST where
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
2015-09-18 15:02:51 +02:00
|
|
|
|
import Data.Int (Int32)
|
2016-01-26 13:38:02 +01:00
|
|
|
|
import Data.String (IsString(fromString))
|
2015-09-26 01:12:22 +02:00
|
|
|
|
import Data.Text (Text, pack)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
|
|
-- * Name
|
|
|
|
|
|
|
|
|
|
type Name = Text
|
|
|
|
|
|
|
|
|
|
-- * Document
|
|
|
|
|
|
|
|
|
|
newtype Document = Document [Definition] deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data Definition = DefinitionOperation OperationDefinition
|
|
|
|
|
| DefinitionFragment FragmentDefinition
|
|
|
|
|
| DefinitionType TypeDefinition
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
2015-09-21 10:05:09 +02:00
|
|
|
|
data OperationDefinition = Query Node
|
|
|
|
|
| Mutation Node
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data Node = Node Name [VariableDefinition] [Directive] SelectionSet
|
|
|
|
|
deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
2015-09-14 11:49:20 +02:00
|
|
|
|
data VariableDefinition = VariableDefinition Variable Type (Maybe DefaultValue)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
newtype Variable = Variable Name deriving (Eq,Show)
|
|
|
|
|
|
2015-09-26 01:12:22 +02:00
|
|
|
|
instance IsString Variable where
|
|
|
|
|
fromString = Variable . pack
|
|
|
|
|
|
2015-09-14 11:49:20 +02:00
|
|
|
|
type SelectionSet = [Selection]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
|
|
data Selection = SelectionField Field
|
|
|
|
|
| SelectionFragmentSpread FragmentSpread
|
|
|
|
|
| SelectionInlineFragment InlineFragment
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
2016-03-09 01:15:46 +01:00
|
|
|
|
{- | <https://facebook.github.io/graphql/#sec-Language.Query-Document.Fields Field Specification>
|
|
|
|
|
|
|
|
|
|
A selection set is primarily composed of fields.
|
|
|
|
|
A field describes one discrete piece of information
|
|
|
|
|
available to request within a selection set.
|
|
|
|
|
|
|
|
|
|
Some fields describe complex data or relationships to other data.
|
|
|
|
|
In order to further explore this data, a field may itself contain
|
|
|
|
|
a selection set, allowing for deeply nested requests.
|
|
|
|
|
All GraphQL operations must specify their selections down to
|
|
|
|
|
fields which return scalar values to ensure an unambiguously
|
|
|
|
|
shaped response.
|
|
|
|
|
|
|
|
|
|
-}
|
2016-01-26 13:38:02 +01:00
|
|
|
|
data Field = Field Alias Name [Argument] [Directive] SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
type Alias = Name
|
|
|
|
|
|
2016-03-09 01:15:46 +01:00
|
|
|
|
{- | <https://facebook.github.io/graphql/#sec-Language.Query-Document.Arguments Argument Specification>
|
|
|
|
|
|
|
|
|
|
Fields are conceptually functions which return values,
|
|
|
|
|
and occasionally accept arguments which alter their behavior.
|
|
|
|
|
These arguments often map directly to function arguments within a
|
|
|
|
|
GraphQL server’s implementation.
|
|
|
|
|
|
|
|
|
|
-}
|
2015-09-12 12:54:05 +02:00
|
|
|
|
data Argument = Argument Name Value deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
-- * Fragments
|
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
|
data FragmentSpread = FragmentSpread Name [Directive]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data InlineFragment =
|
2015-09-13 13:49:11 +02:00
|
|
|
|
InlineFragment TypeCondition [Directive] SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data FragmentDefinition =
|
2015-09-13 13:49:11 +02:00
|
|
|
|
FragmentDefinition Name TypeCondition [Directive] SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
type TypeCondition = NamedType
|
|
|
|
|
|
|
|
|
|
-- * Values
|
|
|
|
|
|
2016-03-09 01:15:46 +01:00
|
|
|
|
{- | <https://facebook.github.io/graphql/#sec-Input-Values Input Value Specification>
|
|
|
|
|
|
|
|
|
|
Field and directive arguments accept input values
|
|
|
|
|
of various literal primitives; input values can be scalars,
|
|
|
|
|
enumeration values, lists, or input objects.
|
|
|
|
|
|
|
|
|
|
If not defined as constant (for example, in DefaultValue),
|
|
|
|
|
input values can be specified as a variable.
|
|
|
|
|
List and inputs objects may also contain
|
|
|
|
|
variables (unless defined to be constant).
|
|
|
|
|
|
|
|
|
|
-}
|
2015-09-12 12:54:05 +02:00
|
|
|
|
data Value = ValueVariable Variable
|
2015-09-18 15:02:51 +02:00
|
|
|
|
| ValueInt Int32
|
|
|
|
|
-- GraphQL Float is double precison
|
2015-09-18 14:55:59 +02:00
|
|
|
|
| ValueFloat Double
|
2015-09-12 12:54:05 +02:00
|
|
|
|
| ValueBoolean Bool
|
2016-02-22 13:59:38 +01:00
|
|
|
|
| ValueString Text
|
2015-09-12 12:54:05 +02:00
|
|
|
|
| ValueEnum Name
|
|
|
|
|
| ValueList ListValue
|
|
|
|
|
| ValueObject ObjectValue
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
newtype ListValue = ListValue [Value] deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
newtype ObjectValue = ObjectValue [ObjectField] deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data ObjectField = ObjectField Name Value deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
type DefaultValue = Value
|
|
|
|
|
|
|
|
|
|
-- * Directives
|
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
|
data Directive = Directive Name [Argument] deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
|
|
-- * Type Reference
|
|
|
|
|
|
|
|
|
|
data Type = TypeNamed NamedType
|
|
|
|
|
| TypeList ListType
|
|
|
|
|
| TypeNonNull NonNullType
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
newtype NamedType = NamedType Name deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
newtype ListType = ListType Type deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data NonNullType = NonNullTypeNamed NamedType
|
|
|
|
|
| NonNullTypeList ListType
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
-- * Type definition
|
|
|
|
|
|
|
|
|
|
data TypeDefinition = TypeDefinitionObject ObjectTypeDefinition
|
|
|
|
|
| TypeDefinitionInterface InterfaceTypeDefinition
|
|
|
|
|
| TypeDefinitionUnion UnionTypeDefinition
|
|
|
|
|
| TypeDefinitionScalar ScalarTypeDefinition
|
|
|
|
|
| TypeDefinitionEnum EnumTypeDefinition
|
|
|
|
|
| TypeDefinitionInputObject InputObjectTypeDefinition
|
|
|
|
|
| TypeDefinitionTypeExtension TypeExtensionDefinition
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
|
data ObjectTypeDefinition = ObjectTypeDefinition Name Interfaces [FieldDefinition]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
type Interfaces = [NamedType]
|
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
|
data FieldDefinition = FieldDefinition Name ArgumentsDefinition Type
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
|
type ArgumentsDefinition = [InputValueDefinition]
|
|
|
|
|
|
2015-09-14 11:49:20 +02:00
|
|
|
|
data InputValueDefinition = InputValueDefinition Name Type (Maybe DefaultValue)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data InterfaceTypeDefinition = InterfaceTypeDefinition Name [FieldDefinition]
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data UnionTypeDefinition = UnionTypeDefinition Name [NamedType]
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data ScalarTypeDefinition = ScalarTypeDefinition Name
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data EnumTypeDefinition = EnumTypeDefinition Name [EnumValueDefinition]
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
newtype EnumValueDefinition = EnumValueDefinition Name
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
data InputObjectTypeDefinition = InputObjectTypeDefinition Name [InputValueDefinition]
|
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
|
|
newtype TypeExtensionDefinition = TypeExtensionDefinition ObjectTypeDefinition
|
|
|
|
|
deriving (Eq,Show)
|