Skip to content

Commit 16c9f42

Browse files
committed
chore: refactor
1 parent 1988a9c commit 16c9f42

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

pkg/engine/datasource/rest_datasource/rest_datasource.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,9 @@ Next:
165165
if !exists {
166166
continue
167167
}
168-
typeRef := p.v.Operation.VariableDefinitions[variableDefRef].Type
169-
typeName := p.v.Operation.TypeNameString(typeRef)
170-
typeKind := p.v.Operation.Types[typeRef].TypeKind
171-
172-
underlyingTypeName := typeName
173-
if typeKind == ast.TypeKindNonNull {
174-
underlyingTypeName = p.v.Operation.TypeNameString(p.v.Operation.Types[typeRef].OfType)
175-
}
176-
177-
node, exists := p.v.Definition.NodeByNameStr(underlyingTypeName)
178-
isEnum := exists && node.Kind == ast.NodeKindEnumTypeDefinition
179168

180169
// if type is a nullable or non-nullable string, add quotes to the raw message
181-
if isEnum || typeName == typeString || (typeKind == ast.TypeKindNonNull && p.v.Operation.TypeNameString(p.v.Operation.Types[typeRef].OfType) == typeString) {
170+
if p.isArgStringOrEnum(variableDefRef) {
182171
query[i].rawMessage = []byte(`"` + query[i].Value + `"`)
183172
} else {
184173
query[i].rawMessage = []byte(query[i].Value)
@@ -195,6 +184,22 @@ Next:
195184
return out
196185
}
197186

187+
func (p *Planner) isArgStringOrEnum(ref int) bool {
188+
argDef := p.v.Operation.VariableDefinitions[ref]
189+
typeName := p.v.Operation.TypeNameString(argDef.Type)
190+
typeDef := p.v.Operation.Types[argDef.Type]
191+
192+
underlyingTypeName := typeName
193+
if typeDef.TypeKind == ast.TypeKindNonNull {
194+
underlyingTypeName = p.v.Operation.TypeNameString(p.v.Operation.Types[argDef.Type].OfType)
195+
}
196+
197+
node, exists := p.v.Definition.NodeByNameStr(underlyingTypeName)
198+
isEnum := exists && node.Kind == ast.NodeKindEnumTypeDefinition
199+
200+
return isEnum || underlyingTypeName == typeString
201+
}
202+
198203
func (p *Planner) marshalQueryParams(params []QueryConfiguration) ([]byte, error) {
199204
marshalled, err := json.Marshal(params)
200205
if err != nil {

0 commit comments

Comments
 (0)