2016-03-15 14:02:34 +01:00
|
|
|
-- | This module defines an abstract syntax tree for the @GraphQL@ language based on
|
|
|
|
-- <https://facebook.github.io/graphql/ Facebook's GraphQL Specification>.
|
2017-01-28 18:15:14 +01:00
|
|
|
--
|
|
|
|
-- Target AST for Parser.
|
2019-07-14 05:58:05 +02:00
|
|
|
module Language.GraphQL.AST
|
|
|
|
( Alias
|
|
|
|
, Argument(..)
|
|
|
|
, Arguments
|
|
|
|
, Definition(..)
|
|
|
|
, Directive(..)
|
|
|
|
, Directives
|
|
|
|
, Document
|
|
|
|
, Field(..)
|
|
|
|
, FragmentDefinition(..)
|
|
|
|
, FragmentName
|
|
|
|
, FragmentSpread(..)
|
|
|
|
, InlineFragment(..)
|
|
|
|
, Name
|
|
|
|
, NonNullType(..)
|
|
|
|
, ObjectField(..)
|
|
|
|
, OperationDefinition(..)
|
|
|
|
, OperationType(..)
|
|
|
|
, Selection(..)
|
|
|
|
, SelectionSet
|
|
|
|
, SelectionSetOpt
|
|
|
|
, Type(..)
|
|
|
|
, TypeCondition
|
|
|
|
, Value(..)
|
|
|
|
, VariableDefinition(..)
|
|
|
|
, VariableDefinitions
|
|
|
|
) where
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2015-09-18 15:02:51 +02:00
|
|
|
import Data.Int (Int32)
|
2017-01-28 18:15:14 +01:00
|
|
|
import Data.List.NonEmpty (NonEmpty)
|
|
|
|
import Data.Text (Text)
|
2019-07-18 05:10:02 +02:00
|
|
|
import Language.GraphQL.AST.Core ( Alias
|
|
|
|
, Name
|
|
|
|
)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
-- * Document
|
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
type Document = NonEmpty Definition
|
|
|
|
|
|
|
|
-- * Operations
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
data Definition = DefinitionOperation OperationDefinition
|
|
|
|
| DefinitionFragment FragmentDefinition
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
data OperationDefinition = OperationSelectionSet SelectionSet
|
|
|
|
| OperationDefinition OperationType
|
2017-02-04 00:08:40 +01:00
|
|
|
(Maybe Name)
|
2017-01-28 18:15:14 +01:00
|
|
|
VariableDefinitions
|
|
|
|
Directives
|
|
|
|
SelectionSet
|
2015-09-21 10:05:09 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
data OperationType = Query | Mutation deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
-- * SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
type SelectionSet = NonEmpty Selection
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
type SelectionSetOpt = [Selection]
|
2015-09-26 01:12:22 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
data Selection = SelectionField Field
|
2015-09-12 12:54:05 +02:00
|
|
|
| SelectionFragmentSpread FragmentSpread
|
|
|
|
| SelectionInlineFragment InlineFragment
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
-- * Field
|
|
|
|
|
|
|
|
data Field = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
-- * Arguments
|
|
|
|
|
|
|
|
type Arguments = [Argument]
|
|
|
|
|
2015-09-12 12:54:05 +02:00
|
|
|
data Argument = Argument Name Value deriving (Eq,Show)
|
|
|
|
|
|
|
|
-- * Fragments
|
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
data FragmentSpread = FragmentSpread Name Directives deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
data InlineFragment = InlineFragment (Maybe TypeCondition) Directives SelectionSet
|
|
|
|
deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
data FragmentDefinition =
|
2017-01-28 18:15:14 +01:00
|
|
|
FragmentDefinition FragmentName TypeCondition Directives SelectionSet
|
|
|
|
deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
type FragmentName = Name
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
type TypeCondition = Name
|
|
|
|
|
2019-07-18 05:10:02 +02:00
|
|
|
-- * Input values
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-07-18 05:10:02 +02:00
|
|
|
data Value = ValueVariable Name
|
|
|
|
| ValueInt Int32
|
|
|
|
| ValueFloat Double
|
|
|
|
| ValueString Text
|
|
|
|
| ValueBoolean Bool
|
2017-01-28 18:15:14 +01:00
|
|
|
| ValueNull
|
2019-07-18 05:10:02 +02:00
|
|
|
| ValueEnum Name
|
|
|
|
| ValueList [Value]
|
|
|
|
| ValueObject [ObjectField]
|
|
|
|
deriving (Eq, Show)
|
2017-01-28 18:15:14 +01:00
|
|
|
|
2019-07-18 05:10:02 +02:00
|
|
|
data ObjectField = ObjectField Name Value deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
-- * Variables
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
type VariableDefinitions = [VariableDefinition]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-07-18 05:10:02 +02:00
|
|
|
data VariableDefinition = VariableDefinition Name Type (Maybe Value)
|
2017-01-28 18:15:14 +01:00
|
|
|
deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-07-18 05:10:02 +02:00
|
|
|
-- * Input types
|
2017-01-28 18:15:14 +01:00
|
|
|
|
|
|
|
data Type = TypeNamed Name
|
|
|
|
| TypeList Type
|
2015-09-12 12:54:05 +02:00
|
|
|
| TypeNonNull NonNullType
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
data NonNullType = NonNullTypeNamed Name
|
|
|
|
| NonNullTypeList Type
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
-- * Directives
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
type Directives = [Directive]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
data Directive = Directive Name [Argument] deriving (Eq,Show)
|