Skip to content

Commit e94853b

Browse files
committed
docs: correct and simplify getting started page
1 parent ee4ad7a commit e94853b

1 file changed

Lines changed: 24 additions & 86 deletions

File tree

docs/src/routes/guide/index.mdx

Lines changed: 24 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ relay-compiler @types/relay-runtime vite-plugin-relay-lite
3030

3131
## Project Setup
3232

33-
### SolidStart Apps
33+
### SolidStart
3434

3535
For SolidStart applications, configure your `app.config.ts`:
3636

@@ -40,21 +40,14 @@ import relay from "vite-plugin-relay-lite";
4040

4141
export default defineConfig({
4242
vite: () => ({
43-
plugins: [
44-
relay({
45-
// Optional: disable code generation if you're handling it separately
46-
codegen: true,
47-
// Optional: path to your relay config
48-
relayConfig: "./relay.config.json"
49-
}),
50-
],
43+
plugins: [relay()],
5144
}),
5245
});
5346
```
5447

55-
### Vite SPAs with Solid Router
48+
### Vite
5649

57-
For Vite-based Single Page Applications using Solid Router, configure your `vite.config.ts`:
50+
For Vite-based applications, configure your `vite.config.ts`:
5851

5952
```typescript
6053
import { defineConfig } from 'vite';
@@ -64,54 +57,11 @@ import relay from 'vite-plugin-relay-lite';
6457
export default defineConfig({
6558
plugins: [
6659
solid(),
67-
relay({
68-
codegen: true,
69-
relayConfig: "./relay.config.json"
70-
}),
60+
relay(),
7161
],
7262
});
7363
```
7464

75-
### Vite SPAs with TanStack Router
76-
77-
For Vite-based SPAs using TanStack Router, the configuration is similar:
78-
79-
```typescript
80-
import { defineConfig } from 'vite';
81-
import solid from 'vite-plugin-solid';
82-
import relay from 'vite-plugin-relay-lite';
83-
84-
export default defineConfig({
85-
plugins: [
86-
solid(),
87-
relay({
88-
codegen: true,
89-
relayConfig: "./relay.config.json"
90-
}),
91-
],
92-
});
93-
```
94-
95-
### TanStack Start
96-
97-
For TanStack Start applications, configure your build setup:
98-
99-
```typescript
100-
import { defineConfig } from '@tanstack/start/config';
101-
import relay from 'vite-plugin-relay-lite';
102-
103-
export default defineConfig({
104-
vite: {
105-
plugins: [
106-
relay({
107-
codegen: true,
108-
relayConfig: "./relay.config.json"
109-
}),
110-
],
111-
},
112-
});
113-
```
114-
11565
## Relay Configuration
11666

11767
Create a `relay.config.json` file in your project root:
@@ -120,7 +70,7 @@ Create a `relay.config.json` file in your project root:
12070
{
12171
"src": "./src",
12272
"schema": "./schema.graphql",
123-
"exclude": ["**/node_modules/**", "**/__mocks__/**", "**/__generated__/**"],
73+
"exclude": ["**/node_modules/**", "**/__generated__/**"],
12474
"language": "typescript",
12575
"eagerEsModules": true
12676
}
@@ -132,31 +82,31 @@ Create a Relay environment to configure your GraphQL client:
13282

13383
```typescript
13484
// src/RelayEnvironment.ts
135-
import { Environment, Network, RecordSource, Store } from 'relay-runtime';
85+
import { Environment, type FetchFunction, Network, RecordSource, Store } from 'relay-runtime';
13686

13787
// Define your fetch function
138-
async function fetchQuery(operation: any, variables: any) {
88+
const fetchFn: FetchFunction = async (params, variables) => {
13989
const response = await fetch('/graphql', {
14090
method: 'POST',
14191
headers: {
14292
'Content-Type': 'application/json',
14393
},
14494
body: JSON.stringify({
145-
query: operation.text,
95+
query: params.text,
14696
variables,
14797
}),
14898
});
14999

150100
return await response.json();
151101
}
152102

153-
// Create Relay environment
154-
const environment = new Environment({
155-
network: Network.create(fetchQuery),
156-
store: new Store(new RecordSource()),
157-
});
158-
159-
export default environment;
103+
export function createRelayEnvironment() {
104+
// Create Relay environment
105+
return new Environment({
106+
network: Network.create(fetchFn),
107+
store: new Store(new RecordSource()),
108+
});
109+
}
160110
```
161111

162112
## Provider Setup
@@ -166,9 +116,11 @@ Wrap your app with the Relay Environment Provider:
166116
```tsx
167117
// src/app.tsx
168118
import { RelayEnvironmentProvider } from 'solid-relay';
169-
import environment from './RelayEnvironment';
119+
import { createRelayEnvironment } from './RelayEnvironment';
170120

171121
function App() {
122+
const environment = createRelayEnvironment();
123+
172124
return (
173125
<RelayEnvironmentProvider environment={environment}>
174126
{/* Your app components */}
@@ -179,20 +131,6 @@ function App() {
179131
export default App;
180132
```
181133

182-
## Running the Relay Compiler
183-
184-
Add scripts to your `package.json`:
185-
186-
```json
187-
{
188-
"scripts": {
189-
"relay": "relay-compiler",
190-
"relay:watch": "relay-compiler --watch",
191-
"dev": "concurrently \"vite dev\" \"relay-compiler --watch\""
192-
}
193-
}
194-
```
195-
196134
## Next Steps
197135

198136
Now that you have Solid Relay set up, you can start using its features:
@@ -217,11 +155,11 @@ The main difference is in the component-level APIs, which Solid Relay provides a
217155

218156
### Plugin Choice
219157

220-
This guide uses `vite-plugin-relay-lite` instead of `vite-plugin-relay`. The lite version is recommended as it provides:
158+
This guide uses [`vite-plugin-relay-lite`](https://github.com/cometkim/vite-plugin-relay-lite) instead of `vite-plugin-relay`. The lite version is recommended as it provides:
221159

222-
- Smaller bundle size
223-
- Better performance
224-
- Essential Relay features without unnecessary overhead
160+
- Better bundler performance
161+
- Smaller install size
225162
- Better integration with modern build tools
163+
- Automatic codegen with Relay Compiler
226164

227-
If you need additional features not available in the lite version, you can switch to `vite-plugin-relay`, but `vite-plugin-relay-lite` covers most use cases effectively.
165+
If you need additional features not available in the lite version, you can switch to `vite-plugin-relay`, but `vite-plugin-relay-lite` covers most use cases effectively.

0 commit comments

Comments
 (0)