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

Add React Query command #26

Merged
merged 3 commits into from
May 3, 2024
Merged

Add React Query command #26

merged 3 commits into from
May 3, 2024

Conversation

stevehanson
Copy link

This follows the template that we previously coded in react-native-templates.

  • Installs React Query
  • Installs testing/mocking utility, MSW
  • Creates a mocking and testing strategy
  • Adds an example API call and mock and test

For now, the "create" command automatically uses React Query, but we will likely decide to prompt the user if they'd like to use this or Apollo (for GraphQL) in the future.

@stevehanson stevehanson force-pushed the react-query branch 2 times, most recently from b135a6e to 8db2362 Compare December 12, 2023 23:16
Copy link
Contributor

@codeofdiego codeofdiego left a comment

Choose a reason for hiding this comment

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

Looking great 👍 Just had a couple of comments and need to fix CI error.

import prependToFile from '../util/prependToFile';

export default async function addReactQuery() {
await addDependency('@tanstack/react-query axios msw');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a check for the individual case when a dependency is already added? I'm wondering if there could be issues when running the addReactQuery alone in an existing project.

/**
* lines should be separated by newlines
*/
export default async function appendToFile(filename: string, lines: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of having both the addToGitignore and the appendToFile to the same fileUtils file? This would keep the src/util leaner and keep related utilities together instead of having 1 file per function.

if (error.message) {
error.message = `Mock for ${request.method} ${
request.url
} was called, but ${message}. Verify that the mocks provided to the test are correct.\n\n${
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice error handling 👍

@rakeshpetit
Copy link
Contributor

I rebased this branch and force pushed.

import Providers, { Provider } from 'src/components/Providers';
import RootNavigator from 'src/navigators/RootNavigator';
import queryClient from '../reactQuery/src/util/api/queryClient';
Copy link
Contributor

@rakeshpetit rakeshpetit Feb 16, 2024

Choose a reason for hiding this comment

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

Suggested change
import queryClient from '../reactQuery/src/util/api/queryClient';
import queryClient from 'src/util/api/queryClient';

I had to change it to this for the App to load the bundler successfully.

Copy link
Contributor

Choose a reason for hiding this comment

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

I fixed this in commit

@rakeshpetit
Copy link
Contributor

rakeshpetit commented Feb 16, 2024

One problem I encountered was the test suite in the created expo app did not exit gracefully. This could be the reason behind CI failure.

image

@stevehanson
Copy link
Author

This command should probably ask the user if they want to use React Query and not automatically install it.

@codeofdiego
Copy link
Contributor

Hi folks, I'm working on this PR as part of Space Station 🛰️

@codeofdiego
Copy link
Contributor

codeofdiego commented Mar 22, 2024

This command should probably ask the user if they want to use React Query and not automatically install it.

@stevehanson Do you mean as part of the standard create app process? The change I'm making right now to make the reactQuery command work independently is to have the QueryClientProvider injected in the App.tsx file by a utility rather than be part of the boilerplate, similar to what we did for hooks.

@stevehanson
Copy link
Author

@codeofdiego yes, as part of createApp is what I was referring to 👍 Sorry for the poorly jotted note.

Stephen Hanson and others added 2 commits May 3, 2024 11:34
This follows the template that [we previously coded in
react-native-templates](https://github.com/thoughtbot/react-native-templates/pull/1/files#diff-fc130cd2eebfc7cbeb229f509cb090c6fb5837a169b9270709cfa73ff46c9a56).

* Installs React Query
* Installs testing/mocking utility, MSW
* Creates a mocking and testing strategy
* Adds an example API call and mock and test

For now, the "create" command automatically uses React Query, but we
will likely decide to prompt the user if they'd like to use this or
Apollo (for GraphQL) in the future.

Co-authored-by: Frida Casas <[email protected]>
@stevehanson stevehanson force-pushed the react-query branch 3 times, most recently from 271cb7d to 203f439 Compare May 3, 2024 17:29
@stevehanson
Copy link
Author

I rebased this PR and updated it per the Trello ticket we defined this morning:

  • Add Tanstack React Query to all new apps for now, as opposed to this being opt-in. Down the line once we support a GraphQL client, we will give users the choice
  • For simplicity, don't allow running this command individually for existing apps. Will just support adding it to new apps for now

New apps currently pull down coffee drinks from an API and display them. We might want to consider a different API and maybe showing results in a separate tab in a follow-up PR.

📸 Screenshot

Note: the bottom tab display issues that can be seen below will be fixed in #44.

image

@stevehanson stevehanson merged commit 21bfc00 into main May 3, 2024
2 checks passed
@stevehanson stevehanson deleted the react-query branch May 3, 2024 19:28
@stevehanson
Copy link
Author

Released in 0.6.1.

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

Successfully merging this pull request may close these issues.

3 participants