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

Handling partial data with error(s) #14

Closed
TimonVS opened this issue Apr 4, 2019 · 6 comments
Closed

Handling partial data with error(s) #14

TimonVS opened this issue Apr 4, 2019 · 6 comments
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@TimonVS
Copy link
Contributor

TimonVS commented Apr 4, 2019

In some cases the API might return partial data with an error, e.g.:

{
  "data": {
    "repository": {
      "ref": null
    }
  },
  "errors": [
    {
      "type": "INVALID_CURSOR_ARGUMENTS",
      "path": [
        "repository",
        "ref",
        "target",
        "history"
      ],
      "locations": [
        {
          "line": 6,
          "column": 11
        }
      ],
      "message": "`123` does not appear to be a valid cursor."
    }
  ]
}

https://github.com/octokit/graphql.js/blob/master/lib/graphql.js#L30 suggests that when the API returns partial data and an error it will just return the data. Now my question is, how can I know that the API returns an error? As far as I can see I can't get access to the error object.

@gr2m gr2m added the Type: Support Any questions, information, or general needs around the SDK or GitHub APIs label Apr 4, 2019
@gr2m
Copy link
Contributor

gr2m commented Apr 4, 2019

Could you maybe make a RunKit notebook reproducing the problem, using nock to mock the response? Or start a pull request with a failing test? You could add it here: https://github.com/octokit/graphql.js/blob/master/test/error-test.js

That would help me to look into it faster 🙏

@TimonVS
Copy link
Contributor Author

TimonVS commented Apr 4, 2019

Sure, I’m sorry for not doing that right away 😅. I’ll get on it ASAP.

@TimonVS
Copy link
Contributor Author

TimonVS commented Apr 4, 2019

I've created a reproduction here: https://github.com/TimonVS/graphql.js/blob/partial-data-error-repro/test/error-test.js#L51

If you run the test it will throw you'll notice that it fails on this line: https://github.com/TimonVS/graphql.js/blob/partial-data-error-repro/test/error-test.js#L103, which means that graphql didn't throw an error even though there are errors in the response. I'm wondering how should we handle partial data with errors? Throwing might not always make sense because the partial data might actually be useful, but if you don't throw then there's no way to know there's an error since result (on https://github.com/TimonVS/graphql.js/blob/partial-data-error-repro/test/error-test.js#L102) only contains the data from mockResponse and not the errors array.

@gr2m
Copy link
Contributor

gr2m commented Apr 4, 2019

The test looks great 👍 Could you start a pull request and we take it from there?

I'm wondering how should we handle partial data with errors?

Good question, clearly a case I did not consider yet. Right now I think I would throw the error, but add error.data with the partial response

@TimonVS
Copy link
Contributor Author

TimonVS commented Apr 4, 2019

Created a PR here: #15

@gr2m
Copy link
Contributor

gr2m commented May 17, 2019

fixed via #15

@gr2m gr2m closed this as completed May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
None yet
Development

No branches or pull requests

2 participants