diff options
Diffstat (limited to 'src/Language/GraphQL/AST')
| -rw-r--r-- | src/Language/GraphQL/AST/DirectiveLocation.hs | 13 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Document.hs | 114 |
2 files changed, 85 insertions, 42 deletions
diff --git a/src/Language/GraphQL/AST/DirectiveLocation.hs b/src/Language/GraphQL/AST/DirectiveLocation.hs index 12c7e18..5b7a36f 100644 --- a/src/Language/GraphQL/AST/DirectiveLocation.hs +++ b/src/Language/GraphQL/AST/DirectiveLocation.hs @@ -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 - ( DirectiveLocation - , ExecutableDirectiveLocation - , TypeSystemDirectiveLocation + ( DirectiveLocation(..) + , ExecutableDirectiveLocation(..) + , TypeSystemDirectiveLocation(..) ) 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 = ExecutableDirectiveLocation ExecutableDirectiveLocation | TypeSystemDirectiveLocation TypeSystemDirectiveLocation deriving (Eq, Show) +-- | Where directives can appear in an executable definition, like a query. data ExecutableDirectiveLocation = Query | Mutation @@ -19,6 +25,7 @@ data ExecutableDirectiveLocation | InlineFragment deriving (Eq, Show) +-- | Where directives can appear in a type system definition. data TypeSystemDirectiveLocation = Schema | Scalar diff --git a/src/Language/GraphQL/AST/Document.hs b/src/Language/GraphQL/AST/Document.hs index 0350ce1..ebe8918 100644 --- a/src/Language/GraphQL/AST/Document.hs +++ b/src/Language/GraphQL/AST/Document.hs @@ -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 ( Definition(..) , Document @@ -17,20 +20,15 @@ import Language.GraphQL.AST ) import Language.GraphQL.AST.DirectiveLocation +-- * Language + +-- ** Document + -- | GraphQL document. type Document = NonEmpty Definition 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. data Definition = ExecutableDefinition ExecutableDefinition @@ -38,70 +36,108 @@ data Definition | TypeSystemExtension TypeSystemExtension deriving (Eq, Show) +-- * Type System + data TypeSystemDefinition = SchemaDefinition [Directive] RootOperationTypeDefinitions | TypeDefinition TypeDefinition | DirectiveDefinition Description Name ArgumentsDefinition DirectiveLocation deriving (Eq, Show) -data SchemaExtension - = SchemaOperationExtension [Directive] RootOperationTypeDefinitions - | SchemaDirectiveExtension (NonEmpty Directive) - deriving (Eq, Show) +-- ** Type System Extensions data TypeSystemExtension = SchemaExtension SchemaExtension | TypeExtension TypeExtension deriving (Eq, Show) -newtype ImplementsInterfaces = ImplementsInterfaces (NonEmpty NamedType) - deriving (Eq, Show) -newtype ImplementsInterfacesOpt = ImplementsInterfacesOpt [NamedType] - deriving (Eq, Show) +-- ** Schema -newtype UnionMemberTypes = UnionMemberTypes (NonEmpty NamedType) - deriving (Eq, Show) -newtype UnionMemberTypesOpt = UnionMemberTypesOpt [NamedType] - deriving (Eq, Show) +type RootOperationTypeDefinitions = NonEmpty RootOperationTypeDefinition -newtype InputFieldsDefinition = InputFieldsDefinition (NonEmpty InputValueDefinition) - deriving (Eq, Show) -newtype InputFieldsDefinitionOpt = InputFieldsDefinitionOpt [InputValueDefinition] +data RootOperationTypeDefinition + = RootOperationTypeDefinition OperationType NamedType deriving (Eq, Show) -data InputValueDefinition - = InputValueDefinition Description Name Type (Maybe Value) [Directive] +data SchemaExtension + = SchemaOperationExtension [Directive] RootOperationTypeDefinitions + | SchemaDirectiveExtension (NonEmpty Directive) deriving (Eq, Show) -newtype ArgumentsDefinition = ArgumentsDefinition [InputValueDefinition] - deriving (Eq, Show) +-- ** Descriptions -data EnumValueDefinition = EnumValueDefinition Description Name [Directive] +newtype Description = Description (Maybe Text) deriving (Eq, Show) -data FieldDefinition = FieldDefinition Description Name ArgumentsDefinition Type - deriving (Eq, Show) +-- ** Types data TypeDefinition = ScalarTypeDefinition Description Name [Directive] - | ObjectTypeDefinition Description Name ImplementsInterfacesOpt [Directive] [FieldDefinition] + | 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 + | 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) + | ObjectTypeFieldsDefinitionExtension + Name ImplementsInterfacesOpt [Directive] (NonEmpty FieldDefinition) + | ObjectTypeDirectivesExtension + Name ImplementsInterfacesOpt (NonEmpty Directive) | ObjectTypeImplementsInterfacesExtension Name ImplementsInterfaces - | InterfaceTypeFieldsDefinitionExtension Name [Directive] (NonEmpty FieldDefinition) + | InterfaceTypeFieldsDefinitionExtension + Name [Directive] (NonEmpty FieldDefinition) | InterfaceTypeDirectivesExtension Name (NonEmpty Directive) | UnionTypeUnionMemberTypesExtension Name [Directive] UnionMemberTypes | UnionDirectivesExtension Name (NonEmpty Directive) - | EnumTypeEnumValuesDefinitionExtension Name [Directive] (NonEmpty EnumValueDefinition) + | EnumTypeEnumValuesDefinitionExtension + Name [Directive] (NonEmpty EnumValueDefinition) | EnumTypeDirectivesExtension Name (NonEmpty Directive) - | InputObjectTypeInputFieldsDefinitionExtension Name [Directive] InputFieldsDefinition + | InputObjectTypeInputFieldsDefinitionExtension + Name [Directive] InputFieldsDefinition | InputObjectTypeDirectivesExtension Name (NonEmpty Directive) deriving (Eq, Show) + +-- ** 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) |
