summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/AST/DirectiveLocation.hs
blob: 600f93143e2d2cf71256aceb5cbffc002eed9ad1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{-# LANGUAGE Safe #-}

-- | 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(..)
    ) 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

instance Show DirectiveLocation where
    show (ExecutableDirectiveLocation directiveLocation) =
        show directiveLocation
    show (TypeSystemDirectiveLocation directiveLocation) =
        show directiveLocation

-- | Where directives can appear in an executable definition, like a query.
data ExecutableDirectiveLocation
    = Query
    | Mutation
    | Subscription
    | Field
    | FragmentDefinition
    | FragmentSpread
    | InlineFragment
    deriving Eq

instance Show ExecutableDirectiveLocation where
    show Query = "QUERY"
    show Mutation = "MUTATION"
    show Subscription = "SUBSCRIPTION"
    show Field = "FIELD"
    show FragmentDefinition = "FRAGMENT_DEFINITION"
    show FragmentSpread = "FRAGMENT_SPREAD"
    show InlineFragment = "INLINE_FRAGMENT"

-- | Where directives can appear in a type system definition.
data TypeSystemDirectiveLocation
    = Schema
    | Scalar
    | Object
    | FieldDefinition
    | ArgumentDefinition
    | Interface
    | Union
    | Enum
    | EnumValue
    | InputObject
    | InputFieldDefinition
    deriving Eq

instance Show TypeSystemDirectiveLocation where
    show Schema = "SCHEMA"
    show Scalar = "SCALAR"
    show Object = "OBJECT"
    show FieldDefinition = "FIELD_DEFINITION"
    show ArgumentDefinition = "ARGUMENT_DEFINITION"
    show Interface = "INTERFACE"
    show Union = "UNION"
    show Enum = "ENUM"
    show EnumValue = "ENUM_VALUE"
    show InputObject = "INPUT_OBJECT"
    show InputFieldDefinition = "INPUT_FIELD_DEFINITION"