@@ -106,6 +106,30 @@ func GetFilterInput(s *ast.Schema, f *ast.Definition) *ast.Definition {
106
106
return s .Types [fmt .Sprintf ("%sFilterInput" , f .Name )]
107
107
}
108
108
109
+ func GetOperationType (ctx context.Context ) OperationType {
110
+ opCtx := graphql .GetOperationContext (ctx )
111
+ if opCtx .Operation .Operation == "mutation" {
112
+ sel := opCtx .Operation .SelectionSet [0 ]
113
+ field := sel .(* ast.Field )
114
+ switch {
115
+ case strings .HasPrefix (field .Name , "delete" ):
116
+ return DeleteOperation
117
+ case strings .HasPrefix (field .Name , "create" ):
118
+ return InsertOperation
119
+ case strings .HasPrefix (field .Name , "update" ):
120
+ return UpdateOperation
121
+ }
122
+ return UnknownOperation
123
+ }
124
+ return QueryOperation
125
+ }
126
+
127
+ func GetAggregateField (parentField , aggField Field ) Field {
128
+ fieldName := strings .Split (aggField .Name , "Aggregate" )[0 ][1 :]
129
+ f , _ := parentField .ForName (fieldName )
130
+ return f
131
+ }
132
+
109
133
func CollectOrdering (ordering interface {}) ([]OrderField , error ) {
110
134
switch orderings := ordering .(type ) {
111
135
case map [string ]interface {}:
@@ -144,30 +168,6 @@ func CollectFields(ctx context.Context, schema *ast.Schema) Field {
144
168
return f
145
169
}
146
170
147
- func GetOperationType (ctx context.Context ) OperationType {
148
- opCtx := graphql .GetOperationContext (ctx )
149
- if opCtx .Operation .Operation == "mutation" {
150
- sel := opCtx .Operation .SelectionSet [0 ]
151
- field := sel .(* ast.Field )
152
- switch {
153
- case strings .HasPrefix (field .Name , "delete" ):
154
- return DeleteOperation
155
- case strings .HasPrefix (field .Name , "create" ):
156
- return InsertOperation
157
- case strings .HasPrefix (field .Name , "update" ):
158
- return UpdateOperation
159
- }
160
- return UnknownOperation
161
- }
162
- return QueryOperation
163
- }
164
-
165
- func GetAggregateField (parentField , aggField Field ) Field {
166
- fieldName := strings .Split (aggField .Name , "Aggregate" )[0 ][1 :]
167
- f , _ := parentField .ForName (fieldName )
168
- return f
169
- }
170
-
171
171
func CollectFromQuery (field * ast.Field , schema * ast.Schema , opCtx * graphql.OperationContext , args map [string ]interface {}) Field {
172
172
f := NewField (nil , field , schema , args )
173
173
f .Selections = collectFields (& f , schema , opCtx , make (map [string ]bool ))
@@ -316,6 +316,7 @@ func buildOrderingHelper(argMap map[string]interface{}) []OrderField {
316
316
return orderFields
317
317
}
318
318
319
+ // parseFieldType returns the fieldType based on the name/directive or type of the *ast.Field
319
320
func parseFieldType (field * ast.Field , typeDef * ast.Definition ) fieldType {
320
321
switch {
321
322
case strings .HasSuffix (field .Name , "Aggregate" ):
0 commit comments