You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
2. A failing test has been provided
3. A local solution has been provided
4. A pull request is pending review
Describe the bug
When adding a custom serialization function to GraphQLEnumType, this serialization function is overwritten by the default serialization function, meaning it is not currently possible to apply a custom serialization function.
I expect the custom serialisation function specified to be called on the enum after the resolver has finished.
Environment:
OS: macOS Venture 13.2.1
@graphql-tools/schema : "9.0.13":
NodeJS: v16.17.0
Additional context
We want to use this to map unknown values returned from datasources to 'UNKNOWN' rather than throwing an error. This would provide a way of doing this globally without having to manually do this at every resolver.
The text was updated successfully, but these errors were encountered:
Thanks for the PR but I don't think we should hijack into graphql-js classes in graphql-tools.
Enum types are not intended to have a custom serialization methods like scalars. Enum's serialization method should be all about internal to external values in my opinion. This looks a bit hack to me.
You can also see here the configuration for enum types doesn't allow to pass a custom serialization method. https://graphql.org/graphql-js/type/#graphqlenumtype
So this is not an issue with graphql-tools.
Thanks for the feedback, coming back to this issue I would agree with your response. We've since reassessed why we wanted this functionality in the first place and come to the realisation that our use of enums might have been innappropriate in this case. Using a string or a custom scalar would definitely be the correct approach.
Issue workflow progress
Progress of the issue based on the Contributor Workflow
Describe the bug
When adding a custom serialization function to
GraphQLEnumType
, this serialization function is overwritten by the default serialization function, meaning it is not currently possible to apply a custom serialization function.To Reproduce
A repo showcasing this bug can be found here https://github.com/rupert648/graphql-tools-serialization-bug-demo
To run the code in this repo, run
yarn && yarn start
. Otherwise follow the following instructions.Create a schema with an enum
Use
mapSchema
onMapperKind.ENUM_TYPE
, and overwrite theGraphQLEnumType
serialization function. Alongside this add a resolver for the queryRun the query against the schema
the expected output is
{ value: "new value
}`Expected behavior
I expect the custom serialisation function specified to be called on the enum after the resolver has finished.
Environment:
@graphql-tools/schema : "9.0.13"
:Additional context
We want to use this to map unknown values returned from datasources to 'UNKNOWN' rather than throwing an error. This would provide a way of doing this globally without having to manually do this at every resolver.
The text was updated successfully, but these errors were encountered: