Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Handle partial GraphQL errors #99

Merged
merged 1 commit into from
Dec 28, 2017
Merged

Handle partial GraphQL errors #99

merged 1 commit into from
Dec 28, 2017

Conversation

mrtnzlml
Copy link
Contributor

@mrtnzlml mrtnzlml commented Dec 28, 2017

Simple workaround for Relay bug (see: facebook/relay#1913).
I have no idea how to write tests for this part of application.
I would prefer to merge this and think about it later since we will
need to refactor it a little bit because of other tests...

Related issue: #98

img_1398

Checklist:

  • it works in landscape and portrait mode
  • it works offline (if possible) otherwise cacheConfig.force=true is used

@mrtnzlml
Copy link
Contributor Author

Please test these changes in Expo after build has finished:

QR Code
exp://exp.host/@mrtnzlml/code-review-handle-partial-errors

Simple workaround for Relay bug (see: facebook/relay#1913).
I have no idea how to write tests for this part of application.
I would prefer to merge this and think about later since we will
need to refactor it a little bit because of other tests...
@mrtnzlml mrtnzlml force-pushed the handle-partial-errors branch from 0b0c2d1 to 4a9f694 Compare December 28, 2017 08:23
@mrtnzlml mrtnzlml requested a review from VaclavSir December 28, 2017 08:23
@mrtnzlml mrtnzlml self-assigned this Dec 28, 2017
Copy link
Contributor

@VaclavSir VaclavSir left a comment

Choose a reason for hiding this comment

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

I also noticed that we create a new relay environment for every call of commitMutation and in the render method of QueryRenderer. Isn't the environment supposed to be a single instance for the whole application?

@@ -11,7 +11,8 @@ Try it in [Expo](https://expo.io/):
* [Project structure](#project-structure)
* [Working with GraphQL API](#working-with-graphql-api)
* [Offline first](#offline-first)
* [Best Practices](#best-practices)
* [Error handling](#error-handling)
* [Best practices](#best-practices)
Copy link
Contributor

Choose a reason for hiding this comment

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

Capital H, capital P.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer first capitals everywhere? I did this change intentionally but I also prefer first capitals everywhere in English headings...

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that I tried to find some arguments, I'm not so sure anymore. There are two main standards - title case and sentence case. Until now I thought the title case is more "correct", but apparently the sentence case is also a valid option. Maybe we can skip this decision for now and continue using the sentence case.

https://en.wikipedia.org/wiki/Letter_case#Headings_and_publication_titles


This should be considered as a valid full response and there should not be any errors. There may be nullable fields, however.

2. GraphQL API returns `data = null` and `errors` field
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to test this scenario by modifying the fetchQuery:

  const fetchQuery = async (operation, variables, cacheConfig) => {
    return {
      data: null,
      errors: [
        {
          message: 'Some message',
        },
      ],
    };

Then I get the following message, is this the expected behavior? Or am I testing it wrong (and how can I test it correctly)?

simulator screen shot - iphone 5s - 2017-12-28 at 15 21 40

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is correct behavior. Data cannot be null because this indicates a fatal GraphQL error and not partial error. See documentation. This is the only situation when Relay actually works correctly and handles errors...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you are pointing to the docs. So yes, this is GeneralError component in action.

@mrtnzlml
Copy link
Contributor Author

I also noticed that we create a new relay environment for every call of commitMutation and in the render method of QueryRenderer. Isn't the environment supposed to be a single instance for the whole application?

Sounds like a mistake but that's not relevant here. I should fix it though. Probably during refactoring of this section, not now. You can create a new issue...

Copy link
Contributor

@VaclavSir VaclavSir left a comment

Choose a reason for hiding this comment

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

OK then.

@VaclavSir
Copy link
Contributor

Issue created #101

@mrtnzlml mrtnzlml merged commit b4a94d1 into master Dec 28, 2017
@mrtnzlml mrtnzlml deleted the handle-partial-errors branch December 28, 2017 15:07
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.

2 participants