-
Notifications
You must be signed in to change notification settings - Fork 844
Open
Labels
Description
The
ID
scalar type represents a unique identifier, often used to
refetch an object or as key for a cache. The ID type appears in a JSON
response as a String; however, it is not intended to be human-readable.
When expected as an input type, any string (such as\"4\"
) or integer
(such as4
) input value will be accepted as an ID.
The ID scalar type accepts string and integer, but in the ParseLiteral
function, it returns everything as a string, even the integers.
var ID = NewScalar(ScalarConfig{
Name: "ID",
Description: "The `ID` scalar type represents a unique identifier, often used to " +
"refetch an object or as key for a cache. The ID type appears in a JSON " +
"response as a String; however, it is not intended to be human-readable. " +
"When expected as an input type, any string (such as `\"4\"`) or integer " +
"(such as `4`) input value will be accepted as an ID.",
Serialize: coerceString,
ParseValue: coerceString,
ParseLiteral: func(valueAST ast.Value) interface{} {
switch valueAST := valueAST.(type) {
case *ast.IntValue:
return valueAST.Value
case *ast.StringValue:
return valueAST.Value
}
return nil
},
})
I think we should change that and resolve it like in the Int
scalar's ParseLiteral
, so a solution would look like this
func(valueAST ast.Value) interface{} {
switch valueAST := valueAST.(type) {
case *ast.IntValue:
if intValue, err := strconv.Atoi(valueAST.Value); err == nil {
return intValue
}
case *ast.StringValue:
return valueAST.Value
}
return nil
}
appleboy, machineghost, ashbuilds and vkapustynskyiheymanhn and DavidJFelix