diff options
| author | Eugen Wissner <belka@caraus.de> | 2019-12-27 09:14:12 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2019-12-27 09:14:12 +0100 |
| commit | 78ee76f9d5bd59e6fe97dfb39ca690a473b256b1 (patch) | |
| tree | e23e9fbd9cd19566edc8bdfd215141eed89d5124 | |
| parent | 56d88310df7c92a1721cc0dfa08a1d232c47c14b (diff) | |
| download | graphql-78ee76f9d5bd59e6fe97dfb39ca690a473b256b1.tar.gz | |
Define schema AST.
Large parts of the schema aren't exported publically. They will be made
public during writing the parser.
Fixes #6.
| -rw-r--r-- | src/Language/GraphQL/AST.hs | 5 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/DirectiveLocation.hs | 13 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Document.hs | 114 |
3 files changed, 86 insertions, 46 deletions
diff --git a/src/Language/GraphQL/AST.hs b/src/Language/GraphQL/AST.hs index 06aeedf..ea7912a 100644 --- a/src/Language/GraphQL/AST.hs +++ b/src/Language/GraphQL/AST.hs @@ -1,7 +1,4 @@ --- | This module defines an abstract syntax tree for the @GraphQL@ language based on --- <https://facebook.github.io/graphql/ Facebook's GraphQL Specification>. --- --- Target AST for Parser. +-- | Target AST for Parser. module Language.GraphQL.AST ( Alias , Argument(..) 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) |
