Description
Hello, I have found what I believe to be an issue (v0.11.3). I'm currently writing a custom type and have found that I cannot interact with null
values. The idea of this snippet is to convert incoming null
values into -1 and to convert outgoing -1 values into null
. Here is a quick snippet of a basic implementation:
new GraphQLScalarType({
name: name,
serialize : val => {
if(val === -1){
return null;
} else {
return val;
}
},
parseValue: val => {
if(val === null) {
return -1;
}
if(Number.isInteger(val) && !isNaN(parseInt(val))){
return parseInt(val);
}
throw "Integer Null Alias: Bad value being parsed";
},
parseLiteral : ast => {
let val = ast.value;
if(val === null) {
return -1;
}
if(!isNaN(parseInt(val))){
return parseInt(val);
}
throw "Integer Null Alias: Bad value in AST";
}
});
What I find is that these methods are called when an integer is sent with the input type, but are not called when null
is sent. Why is that? I've read a bunch of issues/articles relating to this issue, many of them indicating that it has been resolved, but it doesn't seem evident.
I've also seen indications that GraphQL uses null
as an indicator that it should omit fields or auto fill them in.
Why would a framework that is meant to serve as an interface for databases such as SQL take a valid value such as null
and apply side effects to the transmission of that value, extending its purpose beyond that of being a simple value?
Is what I'm trying to do an anti-pattern? If so, what other solutions are there? Is this not an issue? Suggestions?
Thank you! I'm a huge fan of the GraphQL effort, glad to see that its growing so fast.