I have a mutation which has a custom scalar type in the input field,
// Scalar Type
var PLString = new GraphQLScalarType({
name: "PLString",
serialize: value => {
return value
},
parseValue: value => {
return value
},
parseLiteral: ast => {
throw new Error("This string is not valid")
return ast.value
}
})
}
This is my mutation,
mutation: new GraphQLObjectType({
name: 'Mutation',
fields: {
login: {
type: GraphQLString,
args: {
text: { type: PLString }
},
resolve: () => "Immutant"
}
}
});
When I make a graphql mutation like this,
mutation PL {
login(text: "this is text")
}
I get the error
{
"errors": ["This string is not valid"]
}
But when I do this with query variables like this,
mutation PL($input: GraphQLString) {
login(text: $input)
}
//variables
{
"input": "this is text"
}
It succeeds
{
"data": {
"login": "Immutant"
}
}
Is this the expected behavior of GraphQL or is this a problem with the js implementation
Well I have fixed it .. I just needed to throw the error in the parseValue part also and then it works. So that validation logic has to be implemented in the parseLiteral and parseValue functions.
Most helpful comment
Well I have fixed it .. I just needed to throw the error in the parseValue part also and then it works. So that validation logic has to be implemented in the parseLiteral and parseValue functions.