2019-12-27 09:14:12 +01:00
|
|
|
-- | This module defines an abstract syntax tree for the @GraphQL@ language. It
|
|
|
|
-- follows closely the structure given in the specification. Please refer to
|
|
|
|
-- <https://facebook.github.io/graphql/ Facebook's GraphQL Specification>.
|
|
|
|
-- for more information.
|
2019-12-26 13:00:47 +01:00
|
|
|
module Language.GraphQL.AST.Document
|
|
|
|
( Definition(..)
|
|
|
|
, Document
|
|
|
|
, ExecutableDefinition(..)
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.List.NonEmpty (NonEmpty)
|
|
|
|
import Data.Text (Text)
|
|
|
|
import Language.GraphQL.AST
|
|
|
|
( ExecutableDefinition(..)
|
|
|
|
, Directive
|
|
|
|
, Name
|
|
|
|
, OperationType
|
|
|
|
, Type
|
|
|
|
, Value
|
|
|
|
)
|
|
|
|
import Language.GraphQL.AST.DirectiveLocation
|
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
-- * Language
|
|
|
|
|
|
|
|
-- ** Document
|
|
|
|
|
2019-12-26 13:00:47 +01:00
|
|
|
-- | GraphQL document.
|
|
|
|
type Document = NonEmpty Definition
|
|
|
|
|
|
|
|
type NamedType = Name
|
|
|
|
|
|
|
|
-- | All kinds of definitions that can occur in a GraphQL document.
|
|
|
|
data Definition
|
|
|
|
= ExecutableDefinition ExecutableDefinition
|
|
|
|
| TypeSystemDefinition TypeSystemDefinition
|
|
|
|
| TypeSystemExtension TypeSystemExtension
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
-- * Type System
|
|
|
|
|
2019-12-26 13:00:47 +01:00
|
|
|
data TypeSystemDefinition
|
|
|
|
= SchemaDefinition [Directive] RootOperationTypeDefinitions
|
|
|
|
| TypeDefinition TypeDefinition
|
|
|
|
| DirectiveDefinition Description Name ArgumentsDefinition DirectiveLocation
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
-- ** Type System Extensions
|
2019-12-26 13:00:47 +01:00
|
|
|
|
|
|
|
data TypeSystemExtension
|
|
|
|
= SchemaExtension SchemaExtension
|
|
|
|
| TypeExtension TypeExtension
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
-- ** Schema
|
2019-12-26 13:00:47 +01:00
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
type RootOperationTypeDefinitions = NonEmpty RootOperationTypeDefinition
|
2019-12-26 13:00:47 +01:00
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
data RootOperationTypeDefinition
|
|
|
|
= RootOperationTypeDefinition OperationType NamedType
|
2019-12-26 13:00:47 +01:00
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
data SchemaExtension
|
|
|
|
= SchemaOperationExtension [Directive] RootOperationTypeDefinitions
|
|
|
|
| SchemaDirectiveExtension (NonEmpty Directive)
|
2019-12-26 13:00:47 +01:00
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
-- ** Descriptions
|
2019-12-26 13:00:47 +01:00
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
newtype Description = Description (Maybe Text)
|
2019-12-26 13:00:47 +01:00
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2019-12-27 09:14:12 +01:00
|
|
|
-- ** Types
|
2019-12-26 13:00:47 +01:00
|
|
|
|
|
|
|
data TypeDefinition
|
|
|
|
= ScalarTypeDefinition Description Name [Directive]
|
2019-12-27 09:14:12 +01:00
|
|
|
| ObjectTypeDefinition
|
|
|
|
Description Name ImplementsInterfacesOpt [Directive] [FieldDefinition]
|
2019-12-26 13:00:47 +01:00
|
|
|
| InterfaceTypeDefinition Description Name [Directive] [FieldDefinition]
|
|
|
|
| UnionTypeDefinition Description Name [Directive] UnionMemberTypesOpt
|
|
|
|
| EnumTypeDefinition Description Name [Directive] [EnumValueDefinition]
|
2019-12-27 09:14:12 +01:00
|
|
|
| InputObjectTypeDefinition
|
|
|
|
Description Name [Directive] InputFieldsDefinitionOpt
|
2019-12-26 13:00:47 +01:00
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
data TypeExtension
|
|
|
|
= ScalarTypeExtension Name (NonEmpty Directive)
|
2019-12-27 09:14:12 +01:00
|
|
|
| ObjectTypeFieldsDefinitionExtension
|
|
|
|
Name ImplementsInterfacesOpt [Directive] (NonEmpty FieldDefinition)
|
|
|
|
| ObjectTypeDirectivesExtension
|
|
|
|
Name ImplementsInterfacesOpt (NonEmpty Directive)
|
2019-12-26 13:00:47 +01:00
|
|
|
| ObjectTypeImplementsInterfacesExtension Name ImplementsInterfaces
|
2019-12-27 09:14:12 +01:00
|
|
|
| InterfaceTypeFieldsDefinitionExtension
|
|
|
|
Name [Directive] (NonEmpty FieldDefinition)
|
2019-12-26 13:00:47 +01:00
|
|
|
| InterfaceTypeDirectivesExtension Name (NonEmpty Directive)
|
|
|
|
| UnionTypeUnionMemberTypesExtension Name [Directive] UnionMemberTypes
|
|
|
|
| UnionDirectivesExtension Name (NonEmpty Directive)
|
2019-12-27 09:14:12 +01:00
|
|
|
| EnumTypeEnumValuesDefinitionExtension
|
|
|
|
Name [Directive] (NonEmpty EnumValueDefinition)
|
2019-12-26 13:00:47 +01:00
|
|
|
| EnumTypeDirectivesExtension Name (NonEmpty Directive)
|
2019-12-27 09:14:12 +01:00
|
|
|
| InputObjectTypeInputFieldsDefinitionExtension
|
|
|
|
Name [Directive] InputFieldsDefinition
|
2019-12-26 13:00:47 +01:00
|
|
|
| InputObjectTypeDirectivesExtension Name (NonEmpty Directive)
|
|
|
|
deriving (Eq, Show)
|
2019-12-27 09:14:12 +01:00
|
|
|
|
|
|
|
-- ** Objects
|
|
|
|
|
|
|
|
newtype ImplementsInterfaces = ImplementsInterfaces (NonEmpty NamedType)
|
|
|
|
deriving (Eq, Show)
|
|
|
|
newtype ImplementsInterfacesOpt = ImplementsInterfacesOpt [NamedType]
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
data FieldDefinition = FieldDefinition Description Name ArgumentsDefinition Type
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
newtype ArgumentsDefinition = ArgumentsDefinition [InputValueDefinition]
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
data InputValueDefinition
|
|
|
|
= InputValueDefinition Description Name Type (Maybe Value) [Directive]
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
-- ** Unions
|
|
|
|
|
|
|
|
newtype UnionMemberTypes = UnionMemberTypes (NonEmpty NamedType)
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
newtype UnionMemberTypesOpt = UnionMemberTypesOpt [NamedType]
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
-- ** Enums
|
|
|
|
|
|
|
|
data EnumValueDefinition = EnumValueDefinition Description Name [Directive]
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
-- ** Input Objects
|
|
|
|
|
|
|
|
newtype InputFieldsDefinition
|
|
|
|
= InputFieldsDefinition (NonEmpty InputValueDefinition)
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
newtype InputFieldsDefinitionOpt
|
|
|
|
= InputFieldsDefinitionOpt [InputValueDefinition]
|
|
|
|
deriving (Eq, Show)
|