Define schema AST.

Large parts of the schema aren't exported publically. They will be made
public during writing the parser.

Fixes #6.
This commit is contained in:
Eugen Wissner 2019-12-27 09:14:12 +01:00
parent 56d88310df
commit 78ee76f9d5
3 changed files with 90 additions and 50 deletions

View File

@ -1,7 +1,4 @@
-- | This module defines an abstract syntax tree for the @GraphQL@ language based on -- | Target AST for Parser.
-- <https://facebook.github.io/graphql/ Facebook's GraphQL Specification>.
--
-- Target AST for Parser.
module Language.GraphQL.AST module Language.GraphQL.AST
( Alias ( Alias
, Argument(..) , Argument(..)

View File

@ -1,14 +1,20 @@
-- | Various parts of a GraphQL document can be annotated with directives.
-- This module describes locations in a document where directives can appear.
module Language.GraphQL.AST.DirectiveLocation module Language.GraphQL.AST.DirectiveLocation
( DirectiveLocation ( DirectiveLocation(..)
, ExecutableDirectiveLocation , ExecutableDirectiveLocation(..)
, TypeSystemDirectiveLocation , TypeSystemDirectiveLocation(..)
) where ) where
-- | All directives can be splitted in two groups: directives used to annotate
-- various parts of executable definitions and the ones used in the schema
-- definition.
data DirectiveLocation data DirectiveLocation
= ExecutableDirectiveLocation ExecutableDirectiveLocation = ExecutableDirectiveLocation ExecutableDirectiveLocation
| TypeSystemDirectiveLocation TypeSystemDirectiveLocation | TypeSystemDirectiveLocation TypeSystemDirectiveLocation
deriving (Eq, Show) deriving (Eq, Show)
-- | Where directives can appear in an executable definition, like a query.
data ExecutableDirectiveLocation data ExecutableDirectiveLocation
= Query = Query
| Mutation | Mutation
@ -19,6 +25,7 @@ data ExecutableDirectiveLocation
| InlineFragment | InlineFragment
deriving (Eq, Show) deriving (Eq, Show)
-- | Where directives can appear in a type system definition.
data TypeSystemDirectiveLocation data TypeSystemDirectiveLocation
= Schema = Schema
| Scalar | Scalar

View File

@ -1,4 +1,7 @@
-- | This module defines data structures representing a GraphQL document. -- | 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.
module Language.GraphQL.AST.Document module Language.GraphQL.AST.Document
( Definition(..) ( Definition(..)
, Document , Document
@ -17,20 +20,15 @@ import Language.GraphQL.AST
) )
import Language.GraphQL.AST.DirectiveLocation import Language.GraphQL.AST.DirectiveLocation
-- * Language
-- ** Document
-- | GraphQL document. -- | GraphQL document.
type Document = NonEmpty Definition type Document = NonEmpty Definition
type NamedType = Name type NamedType = Name
newtype Description = Description (Maybe Text)
deriving (Eq, Show)
type RootOperationTypeDefinitions = NonEmpty RootOperationTypeDefinition
data RootOperationTypeDefinition
= RootOperationTypeDefinition OperationType NamedType
deriving (Eq, Show)
-- | All kinds of definitions that can occur in a GraphQL document. -- | All kinds of definitions that can occur in a GraphQL document.
data Definition data Definition
= ExecutableDefinition ExecutableDefinition = ExecutableDefinition ExecutableDefinition
@ -38,70 +36,108 @@ data Definition
| TypeSystemExtension TypeSystemExtension | TypeSystemExtension TypeSystemExtension
deriving (Eq, Show) deriving (Eq, Show)
-- * Type System
data TypeSystemDefinition data TypeSystemDefinition
= SchemaDefinition [Directive] RootOperationTypeDefinitions = SchemaDefinition [Directive] RootOperationTypeDefinitions
| TypeDefinition TypeDefinition | TypeDefinition TypeDefinition
| DirectiveDefinition Description Name ArgumentsDefinition DirectiveLocation | DirectiveDefinition Description Name ArgumentsDefinition DirectiveLocation
deriving (Eq, Show) deriving (Eq, Show)
-- ** Type System Extensions
data TypeSystemExtension
= SchemaExtension SchemaExtension
| TypeExtension TypeExtension
deriving (Eq, Show)
-- ** Schema
type RootOperationTypeDefinitions = NonEmpty RootOperationTypeDefinition
data RootOperationTypeDefinition
= RootOperationTypeDefinition OperationType NamedType
deriving (Eq, Show)
data SchemaExtension data SchemaExtension
= SchemaOperationExtension [Directive] RootOperationTypeDefinitions = SchemaOperationExtension [Directive] RootOperationTypeDefinitions
| SchemaDirectiveExtension (NonEmpty Directive) | SchemaDirectiveExtension (NonEmpty Directive)
deriving (Eq, Show) deriving (Eq, Show)
data TypeSystemExtension -- ** Descriptions
= SchemaExtension SchemaExtension
| TypeExtension TypeExtension newtype Description = Description (Maybe Text)
deriving (Eq, Show) deriving (Eq, Show)
-- ** Types
data TypeDefinition
= ScalarTypeDefinition Description Name [Directive]
| ObjectTypeDefinition
Description Name ImplementsInterfacesOpt [Directive] [FieldDefinition]
| InterfaceTypeDefinition Description Name [Directive] [FieldDefinition]
| UnionTypeDefinition Description Name [Directive] UnionMemberTypesOpt
| EnumTypeDefinition Description Name [Directive] [EnumValueDefinition]
| InputObjectTypeDefinition
Description Name [Directive] InputFieldsDefinitionOpt
deriving (Eq, Show)
data TypeExtension
= ScalarTypeExtension Name (NonEmpty Directive)
| ObjectTypeFieldsDefinitionExtension
Name ImplementsInterfacesOpt [Directive] (NonEmpty FieldDefinition)
| ObjectTypeDirectivesExtension
Name ImplementsInterfacesOpt (NonEmpty Directive)
| ObjectTypeImplementsInterfacesExtension Name ImplementsInterfaces
| InterfaceTypeFieldsDefinitionExtension
Name [Directive] (NonEmpty FieldDefinition)
| InterfaceTypeDirectivesExtension Name (NonEmpty Directive)
| UnionTypeUnionMemberTypesExtension Name [Directive] UnionMemberTypes
| UnionDirectivesExtension Name (NonEmpty Directive)
| EnumTypeEnumValuesDefinitionExtension
Name [Directive] (NonEmpty EnumValueDefinition)
| EnumTypeDirectivesExtension Name (NonEmpty Directive)
| InputObjectTypeInputFieldsDefinitionExtension
Name [Directive] InputFieldsDefinition
| InputObjectTypeDirectivesExtension Name (NonEmpty Directive)
deriving (Eq, Show)
-- ** Objects
newtype ImplementsInterfaces = ImplementsInterfaces (NonEmpty NamedType) newtype ImplementsInterfaces = ImplementsInterfaces (NonEmpty NamedType)
deriving (Eq, Show) deriving (Eq, Show)
newtype ImplementsInterfacesOpt = ImplementsInterfacesOpt [NamedType] newtype ImplementsInterfacesOpt = ImplementsInterfacesOpt [NamedType]
deriving (Eq, Show) deriving (Eq, Show)
newtype UnionMemberTypes = UnionMemberTypes (NonEmpty NamedType) data FieldDefinition = FieldDefinition Description Name ArgumentsDefinition Type
deriving (Eq, Show)
newtype UnionMemberTypesOpt = UnionMemberTypesOpt [NamedType]
deriving (Eq, Show) deriving (Eq, Show)
newtype InputFieldsDefinition = InputFieldsDefinition (NonEmpty InputValueDefinition) newtype ArgumentsDefinition = ArgumentsDefinition [InputValueDefinition]
deriving (Eq, Show)
newtype InputFieldsDefinitionOpt = InputFieldsDefinitionOpt [InputValueDefinition]
deriving (Eq, Show) deriving (Eq, Show)
data InputValueDefinition data InputValueDefinition
= InputValueDefinition Description Name Type (Maybe Value) [Directive] = InputValueDefinition Description Name Type (Maybe Value) [Directive]
deriving (Eq, Show) deriving (Eq, Show)
newtype ArgumentsDefinition = ArgumentsDefinition [InputValueDefinition] -- ** Unions
newtype UnionMemberTypes = UnionMemberTypes (NonEmpty NamedType)
deriving (Eq, Show) deriving (Eq, Show)
newtype UnionMemberTypesOpt = UnionMemberTypesOpt [NamedType]
deriving (Eq, Show)
-- ** Enums
data EnumValueDefinition = EnumValueDefinition Description Name [Directive] data EnumValueDefinition = EnumValueDefinition Description Name [Directive]
deriving (Eq, Show) deriving (Eq, Show)
data FieldDefinition = FieldDefinition Description Name ArgumentsDefinition Type -- ** Input Objects
newtype InputFieldsDefinition
= InputFieldsDefinition (NonEmpty InputValueDefinition)
deriving (Eq, Show) deriving (Eq, Show)
data TypeDefinition newtype InputFieldsDefinitionOpt
= ScalarTypeDefinition Description Name [Directive] = InputFieldsDefinitionOpt [InputValueDefinition]
| ObjectTypeDefinition Description Name ImplementsInterfacesOpt [Directive] [FieldDefinition]
| InterfaceTypeDefinition Description Name [Directive] [FieldDefinition]
| UnionTypeDefinition Description Name [Directive] UnionMemberTypesOpt
| EnumTypeDefinition Description Name [Directive] [EnumValueDefinition]
| InputObjectTypeDefinition Description Name [Directive] InputFieldsDefinitionOpt
deriving (Eq, Show)
data TypeExtension
= ScalarTypeExtension Name (NonEmpty Directive)
| ObjectTypeFieldsDefinitionExtension Name ImplementsInterfacesOpt [Directive] (NonEmpty FieldDefinition)
| ObjectTypeDirectivesExtension Name ImplementsInterfacesOpt (NonEmpty Directive)
| ObjectTypeImplementsInterfacesExtension Name ImplementsInterfaces
| InterfaceTypeFieldsDefinitionExtension Name [Directive] (NonEmpty FieldDefinition)
| InterfaceTypeDirectivesExtension Name (NonEmpty Directive)
| UnionTypeUnionMemberTypesExtension Name [Directive] UnionMemberTypes
| UnionDirectivesExtension Name (NonEmpty Directive)
| EnumTypeEnumValuesDefinitionExtension Name [Directive] (NonEmpty EnumValueDefinition)
| EnumTypeDirectivesExtension Name (NonEmpty Directive)
| InputObjectTypeInputFieldsDefinitionExtension Name [Directive] InputFieldsDefinition
| InputObjectTypeDirectivesExtension Name (NonEmpty Directive)
deriving (Eq, Show) deriving (Eq, Show)