Skip to content
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

Successful responses with null data are rejected as errors #28

Closed
pimterry opened this issue Oct 6, 2020 · 1 comment
Closed

Successful responses with null data are rejected as errors #28

pimterry opened this issue Oct 6, 2020 · 1 comment

Comments

@pimterry
Copy link

pimterry commented Oct 6, 2020

My API includes mutations that don't return any data. They're effectively requests for a low-priority async operation, and they return almost immediately with no information, by just returning null.

That's works fine and its perfectly valid GraphQL as far as I'm aware, but this library rejects these responses, due to

fetchql/src/index.js

Lines 192 to 196 in 07d08be

// if all properties of data is 'null'
const allDataKeyEmpty = Object.keys(data).every(key => !data[key]);
if (allDataKeyEmpty) {
return reject(errors);
}

In that code, a successful response that has no errors but which returns a { myOperation: null } result will throw undefined.

I don't think this case should throw. Even if it does, it should probably throw something clearer than undefined.

@gucheen
Copy link
Owner

gucheen commented Oct 7, 2020

According to GraphQL's specification, in 7.1.1 https://spec.graphql.org/June2018/#sec-Data

if the operation was a mutation, this output will be an object of the schema’s mutation root type.

It's better to return the root type of mutation. I would like to respect the specification.

@gucheen gucheen closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants