Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Always return null#133

Open
peggyrayzis wants to merge 1 commit intomasterfrom
return-null
Open

Always return null#133
peggyrayzis wants to merge 1 commit intomasterfrom
return-null

Conversation

@peggyrayzis
Copy link
Copy Markdown
Contributor

GraphQL servers never return undefined, always null. We need to also return null from resolvers without a return value to avoid warnings in Apollo Client.

info.resultKey || fieldName
];
if (resolve) return resolve(rootValue, args, context, info);
if (resolve) return resolve(rootValue, args, context, info) || null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a check for only undefined, because the resolver might return 0 or false by design.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what if it's an async resolver? A promise will always be truthy, even if it resolves to undefined.

@fbartho
Copy link
Copy Markdown
Contributor

fbartho commented Jan 7, 2018

Hey @peggyrayzis -- I think this PR is still needed (-- do you concur?), but @jamiter made some good points. Is this something you're coming back to? Or would you like someone to collaborate on this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants