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
|
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | GraphQL document.
|
2017-01-28 18:15:14 +01:00
|
|
|
type Document = NonEmpty Definition
|
|
|
|
|
|
|
|
-- * Operations
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Top-level definition of a document, either an operation or a fragment.
|
2019-10-01 06:59:30 +02:00
|
|
|
data Definition
|
|
|
|
= DefinitionOperation OperationDefinition
|
|
|
|
| DefinitionFragment FragmentDefinition
|
|
|
|
deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Operation definition.
|
2019-10-01 06:59:30 +02:00
|
|
|
data OperationDefinition
|
|
|
|
= OperationSelectionSet SelectionSet
|
|
|
|
| OperationDefinition OperationType
|
|
|
|
(Maybe Name)
|
|
|
|
[VariableDefinition]
|
|
|
|
[Directive]
|
|
|
|
SelectionSet
|
|
|
|
deriving (Eq, Show)
|
2015-09-21 10:05:09 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | GraphQL has 3 operation types: queries, mutations and subscribtions.
|
|
|
|
--
|
|
|
|
-- Currently only queries and mutations are supported.
|
|
|
|
data OperationType = Query | Mutation deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- * Selections
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | "Top-level" selection, selection on a operation.
|
2017-01-28 18:15:14 +01:00
|
|
|
type SelectionSet = NonEmpty Selection
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-09-25 05:35:36 +02:00
|
|
|
-- | Field selection.
|
2017-01-28 18:15:14 +01:00
|
|
|
type SelectionSetOpt = [Selection]
|
2015-09-26 01:12:22 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Single selection element.
|
|
|
|
data Selection
|
2019-10-01 06:59:30 +02:00
|
|
|
= SelectionField Field
|
2019-08-29 07:40:50 +02:00
|
|
|
| SelectionFragmentSpread FragmentSpread
|
|
|
|
| SelectionInlineFragment InlineFragment
|
|
|
|
deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
-- * Field
|
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | GraphQL field.
|
|
|
|
data Field
|
2019-10-01 06:59:30 +02:00
|
|
|
= Field (Maybe Alias) Name [Argument] [Directive] SelectionSetOpt
|
2019-08-29 07:40:50 +02:00
|
|
|
deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2017-01-28 18:15:14 +01:00
|
|
|
-- * Arguments
|
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Argument list.
|
2019-10-01 06:59:30 +02:00
|
|
|
{-# DEPRECATED Arguments "Use [Argument] instead" #-}
|
2017-01-28 18:15:14 +01:00
|
|
|
type Arguments = [Argument]
|
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Argument.
|
2015-09-12 12:54:05 +02:00
|
|
|
data Argument = Argument Name Value deriving (Eq,Show)
|
|
|
|
|
|
|
|
-- * Fragments
|
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Fragment spread.
|
2019-10-01 06:59:30 +02:00
|
|
|
data FragmentSpread = FragmentSpread Name [Directive] deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Inline fragment.
|
2019-10-01 06:59:30 +02:00
|
|
|
data InlineFragment = InlineFragment (Maybe TypeCondition) [Directive] SelectionSet
|
2019-08-29 07:40:50 +02:00
|
|
|
deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Fragment definition.
|
|
|
|
data FragmentDefinition
|
2019-10-01 06:59:30 +02:00
|
|
|
= FragmentDefinition Name TypeCondition [Directive] SelectionSet
|
2019-08-29 07:40:50 +02:00
|
|
|
deriving (Eq, Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
{-# DEPRECATED FragmentName "Use Name instead" #-}
|
2017-01-28 18:15:14 +01:00
|
|
|
type FragmentName = Name
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Type condition.
|
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-08-29 07:40:50 +02:00
|
|
|
-- | Input value.
|
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-08-29 07:40:50 +02:00
|
|
|
-- | Key-value pair.
|
|
|
|
--
|
|
|
|
-- A list of 'ObjectField's represents a GraphQL object type.
|
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
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Variable definition list.
|
2019-10-01 06:59:30 +02:00
|
|
|
{-# DEPRECATED VariableDefinitions "Use [VariableDefinition] instead" #-}
|
2017-01-28 18:15:14 +01:00
|
|
|
type VariableDefinitions = [VariableDefinition]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Variable definition.
|
2019-07-18 05:10:02 +02:00
|
|
|
data VariableDefinition = VariableDefinition Name Type (Maybe Value)
|
2019-08-29 07:40:50 +02: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
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Type representation.
|
2017-01-28 18:15:14 +01:00
|
|
|
data Type = TypeNamed Name
|
|
|
|
| TypeList Type
|
2015-09-12 12:54:05 +02:00
|
|
|
| TypeNonNull NonNullType
|
2019-08-29 07:40:50 +02:00
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Helper type to represent Non-Null types and lists of such types.
|
2017-01-28 18:15:14 +01:00
|
|
|
data NonNullType = NonNullTypeNamed Name
|
|
|
|
| NonNullTypeList Type
|
2019-08-29 07:40:50 +02:00
|
|
|
deriving (Eq, Show)
|
2017-01-28 18:15:14 +01:00
|
|
|
|
|
|
|
-- * Directives
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Directive list.
|
2019-10-01 06:59:30 +02:00
|
|
|
{-# DEPRECATED Directives "Use [Directive] instead" #-}
|
2017-01-28 18:15:14 +01:00
|
|
|
type Directives = [Directive]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
2019-08-29 07:40:50 +02:00
|
|
|
-- | Directive.
|
|
|
|
data Directive = Directive Name [Argument] deriving (Eq, Show)
|