Add custom coercion entry point in ValuesResolver #3120
rciummo-linkedin
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, this is Rosa from linkedin. I want to add an entry point for custom coercion in ValuesResolver.json
Essentially, I'd want to keep the current coerceVariableValues and add another flavor of it that takes a Function<Object, Object> preCoercionFunction.
This would get passed to ValuesResolverConversion.externalValueToInternalValueForVariables where if not-null, would translate the value right before this line here
As I understand, the custom scalars now have strict coercing as of v20. At linkedIn, our APIs pass around a custom null class instance to represent null (say Data.NULL) instead of the java null. This is an issue for us even pre-v20 because this Data.null instance is converting to a string "null" instead of java null. To work around this we are rebuilding the entire rawVariables map to convert Data.NULL to null before parsing our raw input variables. However, we have found that this may be causing performance issues so we would like a way to be able to do our custom conversions while still using the grapql native scalars.
The reason we want to not build our own scalars is because currently our APIs are using schemas with the native scalars and creating a new type would make all of our schema backwards incompatible which is not an option for us.
So from our example, our function would look like:
Function<Object, Object> preCoercion = input -> { return (input == Data.NULL) ? null : input}
Any thoughts? @bbakerman
Beta Was this translation helpful? Give feedback.
All reactions