Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Query component uses hook #1519

Merged
merged 4 commits into from
Jun 24, 2020
Merged

Conversation

CameronGorrie
Copy link
Contributor

@CameronGorrie CameronGorrie commented Jun 17, 2020

Description

Fixes #1475

Client-side queries are being executed on the server when using the Apollo Query component re-exported from react-graphql. This PR replaces the declarative component with our own implementation which uses the custom useQuery hook and handles client-only queries correctly.

Type of change

  • react-graphql Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above (Documentation fix and Test update does not need a changelog as we do not publish new version)

@CameronGorrie CameronGorrie self-assigned this Jun 17, 2020
@CameronGorrie CameronGorrie force-pushed the react-graphql-declarative-query branch 2 times, most recently from 3488a16 to 5881b46 Compare June 17, 2020 22:30
@CameronGorrie CameronGorrie force-pushed the react-graphql-declarative-query branch 2 times, most recently from fa69544 to ec214d2 Compare June 17, 2020 23:13
@CameronGorrie CameronGorrie force-pushed the react-graphql-declarative-query branch 3 times, most recently from 60c4306 to 13a8a23 Compare June 23, 2020 15:01
@CameronGorrie CameronGorrie force-pushed the react-graphql-declarative-query branch from 92e0e26 to 105ae94 Compare June 23, 2020 19:26
Copy link
Contributor

@helloneele helloneele left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Collaborator

@vsumner vsumner left a comment

Choose a reason for hiding this comment

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

LGTM! I added a few questions.

}: QueryComponentOptions<Data, Variables>) {
const opts = [options] as IfAllNullableKeys<
Variables,
[QueryHookOptions<Data, NoInfer<Variables>>?],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should there be a ? in there?

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 it should. Chris added some context regarding the query options type here: #1519 (comment)

const graphQL = createGraphQL({PetQuery: mockData});
const renderPropSpy = jest.fn(() => null);

await mountWithGraphQL(<Query query={petQuery}>{renderPropSpy}</Query>, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! This is a great start. I'd also love to add a way to test the SSR issue that this component solves. But I don't think that is required for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add a set of tests to ensure SSR behaviour. Do you feel these are implementation details of useQuery that are already tested though? https://github.com/Shopify/quilt/blob/master/packages/react-graphql/src/hooks/tests/query-ssr.test.tsx

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was referring to the double call on ssr., but I think we have good coverage overall.

@@ -25,7 +25,6 @@
"homepage": "https://github.com/Shopify/quilt/blob/master/packages/react-graphql/README.md",
"dependencies": {
"@apollo/react-common": ">=3.0.0 <4.0.0",
"@apollo/react-components": ">=3.0.0 <4.0.0",
"@apollo/react-hooks": ">=3.0.0 <4.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this have been removed?

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. Before this package was just re-exporting the Query component from Apollo which was imported from @apollo/react-components. Now that we're defining our own component the import can be safely removed.

@CameronGorrie CameronGorrie merged commit f9b38fd into master Jun 24, 2020
@CameronGorrie CameronGorrie deleted the react-graphql-declarative-query branch June 24, 2020 13:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSR false queries called on the server
4 participants