From f6ff0ab9c785273e3ceeac6b9d636c5ec519a008 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 7 Sep 2020 22:01:49 +0200 Subject: Validate fragments on composite types --- src/Language/GraphQL/AST/Document.hs | 41 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src/Language/GraphQL/AST/Document.hs') diff --git a/src/Language/GraphQL/AST/Document.hs b/src/Language/GraphQL/AST/Document.hs index f780a9d..5cfadc5 100644 --- a/src/Language/GraphQL/AST/Document.hs +++ b/src/Language/GraphQL/AST/Document.hs @@ -17,7 +17,9 @@ module Language.GraphQL.AST.Document , ExecutableDefinition(..) , FieldDefinition(..) , FragmentDefinition(..) + , FragmentSpread(..) , ImplementsInterfaces(..) + , InlineFragment(..) , InputValueDefinition(..) , Location(..) , Name @@ -132,7 +134,28 @@ type SelectionSetOpt = [Selection] -- } -- } -- @ +data Selection + = Field (Maybe Alias) Name [Argument] [Directive] SelectionSetOpt Location + | FragmentSpreadSelection FragmentSpread + | InlineFragmentSelection InlineFragment + deriving (Eq, Show) + +-- Inline fragments don't have any name and the type condition ("on UserType") +-- is optional. -- +-- @ +-- { +-- user { +-- ... on UserType { +-- id +-- name +-- } +-- } +-- @ +data InlineFragment = InlineFragment + (Maybe TypeCondition) [Directive] SelectionSet Location + deriving (Eq, Show) + -- A fragment spread refers to a fragment defined outside the operation and is -- expanded at the execution time. -- @@ -148,23 +171,7 @@ type SelectionSetOpt = [Selection] -- name -- } -- @ --- --- Inline fragments are similar but they don't have any name and the type --- condition ("on UserType") is optional. --- --- @ --- { --- user { --- ... on UserType { --- id --- name --- } --- } --- @ -data Selection - = Field (Maybe Alias) Name [Argument] [Directive] SelectionSetOpt Location - | FragmentSpread Name [Directive] Location - | InlineFragment (Maybe TypeCondition) [Directive] SelectionSet Location +data FragmentSpread = FragmentSpread Name [Directive] Location deriving (Eq, Show) -- ** Arguments -- cgit v1.2.3