-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix: Handle null values for optional types #21
Conversation
Without this change `apollo-link-scalars` will error for valid `null` values of nullable types with hard to track down errors like: ``` TypeError: String cannot represent a non string value: null ``` With this change, I'm able to get `apollo-link-scalars` for my project.
@@ -169,7 +169,7 @@ describe("scalar returned directly from first level queries", () => { | |||
expect.assertions(1); | |||
}); | |||
|
|||
it("override the scala resolvers with the custom functions map", done => { | |||
it("override the scalar resolvers with the custom functions map", done => { |
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.
d'oh… thanks :)
@@ -66,6 +66,8 @@ export class Parser { | |||
fieldNode: ReducedFieldNode | |||
): any { | |||
const type = ensureNullableType(value, givenType, fieldNode); | |||
if (isNone(value)) return value; |
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.
good point. Originally I was thinking of allowing some custom parsing on nulls on scalars. Later I decided against it but I never went back and change the code. Nice one.
@gsamokovarov nice one. Thanks! |
v0.1.4 released with this fix |
Thank you for the quick reaction! |
@all-contributors please add @gsamokovarov for bug, tests and code |
I've put up a pull request to add @gsamokovarov! 🎉 |
Without this change, I'm not able to get
apollo-link-scalars
running in my project.This is a bugfix.
apollo-link-scalars
errors for validnull
values of nullable types with errors like:The errors are hard to track down as they occur during the Apollo client initialization.
apollo-link-scalars
won't error on nullable scalar types anymore.