You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Iteration on new quick start guide based on feedback (#4966)
Summary:Based on feedback from cpojer (some of which echoed other feedback I've received), this updates the new quickstart guide to clarify some details:1. Configures babel plugin via the Vite React plugin rather than needing to use the vite Relay plugin2. Clarifies what `relay.config.json` is for3. Clarifies that the `<RelayEnvironmentPrivider>` must nest around all other components.4. Adds defining a fragment component to the guide (echoing feedback evanyeung gave earlier).5. Clarify what running the compiler doesPull Requestresolved:#4966Reviewed By: evanyeungDifferential Revision: D73519975Pulled By: captbaritonefbshipit-source-id: eb45049c5ac89bc133840a6ecbd3ce3726968bc9
Copy file name to clipboardExpand all lines: website/docs/getting-started/quick-start.md
+50-17Lines changed: 50 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -29,32 +29,30 @@ You’ll be prompted for a project name. Type: `relay-example`
29
29
```bash
30
30
cd relay-example
31
31
32
-
# Note: Version 18^ of Relay is missing React 19 as a peer dependency. This will be fixed in the next release. Until then we must add `--force` to the following commands.
32
+
# Note: Version 18^ of Relay is missing React 19 as a peer dependency. To avoid
33
+
# this, we are using the `@main` versions of the Relay packages until the next Relay release
Relay uses a[Babel plugin](./babel-plugin.md) to insert code generated by the Relay compiler into your bundle. We can enablethat transform in Vite withthe`vite-plugin-relay`plugin:
45
+
Relay uses a[Babel plugin](./babel-plugin.md) to insert code generated by the Relay compiler into your bundle. We can enablethe Relay Babel plugin we installed earliery by configuringtheReact Viteplugin.
45
46
46
47
```tsx title="vite.config.ts"
47
48
import {defineConfig }from'vite'
48
49
importreactfrom'@vitejs/plugin-react'
49
-
// change-line
50
-
importrelayfrom'vite-plugin-relay';
51
50
52
51
// https://vite.dev/config/
53
52
exportdefaultdefineConfig({
54
53
plugins: [
55
-
react(),
56
54
// change-line
57
-
relay
55
+
react({ babel: { plugins: ["relay"] } })
58
56
],
59
57
})
60
58
```
@@ -63,12 +61,14 @@ See [Babel Plugin](./babel-plugin.md) for information about how to configure the
63
61
64
62
##Configure the Relay Compiler
65
63
66
-
Next we will download the schema for the Star Wars GraphQL endpoint and configure the Relay compiler to use that schema:
64
+
Next we will download theGraphQLschema for the Star Wars GraphQL endpoint.
And define our`relay.config.json` config file which tells the[Relay Compiler](./compiler.md) which schema file we want it to use and other details about our project.
See[Relay Environment](../api-reference/relay-runtime/relay-environment.md) for an overview of the Relay Environment and how to configure it.
132
132
133
+
:::tip
134
+
`<RelayEnvironmentProvider>` exposes your Environment via[React context](https://react.dev/learn/passing-data-deeply-with-context), so it must wrap your entire application.
135
+
:::
136
+
133
137
##Define your first Relay component
134
138
135
-
Finally we can start defining the data we want to fetch and build our UI:
139
+
Finally we can start defining the data we want to fetch and build our UI. Our app will fetch a list of films and render each one using a`<Film>` component.
@@ -145,8 +150,7 @@ export default function App() {
145
150
allFilms {
146
151
films {
147
152
id
148
-
title
149
-
director
153
+
...Film_item
150
154
}
151
155
}
152
156
}
@@ -160,21 +164,48 @@ export default function App() {
160
164
<div>
161
165
<h1>Star Wars Films</h1>
162
166
{films?.map((film)=> (
163
-
<likey={film.id}>
164
-
<b>{film.title}</b>: directed by <i>{film.director}</i>
165
-
</li>
167
+
<Filmkey={film.id}film={film} />
166
168
))}
167
169
</div>
168
170
);
169
171
}
170
172
```
171
173
174
+
##Define your first fragment
175
+
176
+
One of Relay's core principles is that each component should define its own data dependencies. So, we define our`<Film>` component using a[GraphQL Fragment](https://graphql.org/learn/queries/#fragments).
<b>{film.title}</b>: directed by <i>{film.director}</i>
196
+
</li>
197
+
);
198
+
}
199
+
```
200
+
172
201
##Compile and run your app
173
202
174
203
All that’s left is to run the Relay compiler and start your app!
175
204
205
+
The Relay compiler generates TypeScript types and combines your queries and fragments into optimized representations. You have to run the Relay compiler each time you modify your GraphQL queries or fragments.
206
+
176
207
:::tip
177
-
If you have[Watchman](https://facebook.github.io/watchman/) installed, run`echo "{}" > .watchmanconfig` to create a Watchman root.
208
+
If you have[Watchman](https://facebook.github.io/watchman/) installed you can run`npx relay-compiler --watch` to have the compiler run in watch mode, but you'll need to run`echo "{}" > .watchmanconfig` to create a Watchman root.
178
209
:::
179
210
180
211
```bash
@@ -183,3 +214,5 @@ npm run dev
183
214
```
184
215
185
216
You should now be able to open your app in a browser:[http://localhost:5173/](http://localhost:5173/)