-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Switch GraphQLScalarType methods to callbacks #1412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
extensionASTNodes, | ||
serialize: type._scalarConfig.serialize, | ||
parseValue: type._scalarConfig.parseValue, | ||
parseLiteral: type._scalarConfig.parseLiteral, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment to copy scalar config you should either use type._scalarConfig.serialize
or type.serialize.bind(type)
.
This is a big problem for 3rd-party libraries doing schema transformations.
@IvanGoncharov sorry I feel like I'm missing context on this: it seems like an improvement based purely on the fact that the flow types are better, but other than that I am not sure I see why this is desired? The change is straightforward enough I may merge regardless, but wanted to understand your logic. |
@mjmahone For example, I want to add a prefix to every type in a schema: function prefixType(type: GraphQLNamedType, prefix: string): GraphQLNamedType {
if (isScalarType(type)) {
return new GraphQLScalarType({
name: prefix + type.name,
// ...
parseLiteral: type.parseLiter,
});
}
// ...
} And Moreover you either need to use private property |
|
||
// Serializes an internal value to include in a response. | ||
serialize(value: mixed): mixed { | ||
const serializer = this._scalarConfig.serialize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like an improvement based purely on the fact that the flow types are better
@mjmahone This wrapper function depends on this
so before proposed change you can't do:
const serialize = GraphQLString.serialize;
serialize(5);
// TypeError: Cannot read property '_scalarConfig' of undefined
Or more complicated scenario:
const newScalar = new GraphQLScalarType({
name: GraphQLString.name,
serialize: GraphQLString.serialize,
});
console.log(GraphQLString.serialize(5))
// 5
console.log(newScalar.serialize(5))
// TypeError: Cannot read property '_scalarConfig' of undefined
Great, thanks for the context @IvanGoncharov ! |
No description provided.