forked from fsprojects/FSharp.Data.GraphQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAst.fs
More file actions
193 lines (166 loc) · 4.33 KB
/
Copy pathAst.fs
File metadata and controls
193 lines (166 loc) · 4.33 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/// The MIT License (MIT)
/// Copyright (c) 2016 Bazinga Technologies Inc
namespace FSharp.Data.GraphQL.Ast
//NOTE: For references, see https://facebook.github.io/graphql/
/// 2.2 Query Document
type Document = {
Definitions: Definition list
}
and Definition =
| OperationDefinition of OperationDefinition
| FragmentDefinition of FragmentDefinition
member x.Name =
match x with
| OperationDefinition op -> op.Name
| FragmentDefinition frag -> frag.Name
member x.Directives =
match x with
| OperationDefinition op -> op.Directives
| FragmentDefinition frag -> frag.Directives
member x.SelectionSet =
match x with
| OperationDefinition op -> op.SelectionSet
| FragmentDefinition frag -> frag.SelectionSet
/// 2.2.1 Operations
and OperationDefinition = {
OperationType: OperationType
Name: string option
VariableDefinitions: VariableDefinition list
Directives: Directive list
SelectionSet: Selection list
}
and OperationType =
| Query
| Mutation
| Subscription
/// 2.2.2 Selection Sets
and Selection =
| Field of Field
| FragmentSpread of FragmentSpread
/// 2.2.6.2 Inline Fragments
| InlineFragment of FragmentDefinition
member x.Directives =
match x with
| Field f -> f.Directives
| FragmentSpread s -> s.Directives
| InlineFragment f -> f.Directives
/// 2.2.3 Fields
and Field =
{
/// 2.2.5 Field Alias
Alias: string option
Name: string
Arguments: Argument list
Directives: Directive list
SelectionSet: Selection list
}
member x.AliasOrName =
match x.Alias with
| Some alias -> alias
| None -> x.Name
/// 2.2.4 Arguments
and Argument = {
Name: string
Value: Value
}
/// 2.2.6 Fragments
and FragmentSpread = {
Name: string
Directives: Directive list
}
and FragmentDefinition = {
Name: string option
/// 2.2.6.1 Type Conditions
TypeCondition: string option
Directives: Directive list
SelectionSet: Selection list
}
/// 2.9 Input Values
and Value =
/// 2.9.1 Int Value
| IntValue of int64
/// 2.9.2 Float Value
| FloatValue of double
/// 2.9.3 Boolean Value
| BooleanValue of bool
/// 2.9.4 String Value
| StringValue of string
/// 2.9.5 Null Value
| NullValue
/// 2.9.6 Enum Value
| EnumValue of string
/// 2.9.7 List Value
| ListValue of Value list
/// 2.9.8 Input Object Values
| ObjectValue of Map<string, Value>
/// 2.10 Variables
| Variable of string
/// 2.2.8 Variables
and VariableDefinition =
{ VariableName: string
Type: InputType
DefaultValue: Value option }
/// 2.2.9 Input Types
and InputType =
| NamedType of string
| ListType of InputType
| NonNullType of InputType
override x.ToString() =
let rec str = function
| NamedType name -> name
| ListType inner -> "[" + (str inner) + "]"
| NonNullType inner -> (str inner) + "!"
str x
/// 2.2.10 Directives
and Directive =
{
Name: string
Arguments: Argument list
}
member x.If = x.Arguments |> List.find (fun arg -> arg.Name = "if")
// Type System Definition
and OperationTypeDefinition = {
Type: string
Operation: OperationType
}
and SchemaDefintion = {
OperationTypes: OperationTypeDefinition
}
and ObjectTypeDefinition = {
Name: string
Interfaces: string []
Fields: FieldDefinition []
}
and FieldDefinition = {
Name: string
Arguments: InputValueDefinition []
Type: InputType
}
and InputValueDefinition = {
Name: string
Type: InputType
DefaultValue: Value option
}
and InterfaceTypeDefinition = {
Name: string
Fields: FieldDefinition []
}
and UnionTypeDefinition = {
Name: string
Types: string []
}
and EnumTypeDefinition = {
Name: string
Values: string []
}
and InputObjectTypeDefinition = {
Name: string
Fields: InputValueDefinition []
}
and TypeDefinition =
| ScalarTypeDefinition of string
| ObjectTypeDefinition of ObjectTypeDefinition
| InterfaceTypeDefinition of InterfaceTypeDefinition
| UnionTypeDefinition of UnionTypeDefinition
| EnumTypeDefinition of EnumTypeDefinition
| InputObjectTypeDefinition of InputObjectTypeDefinition