@carvajalconsultants/headstart 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +20 -15
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -12,10 +12,15 @@ This library is made up of:
12
12
 
13
13
  1. Initialize Tanstack Start as per: https://tanstack.com/router/latest/docs/framework/react/start/getting-started
14
14
 
15
- 2. Install Postgraphile as a library as per: https://tanstack.com/router/latest/docs/framework/react/start/getting-started
15
+ 2. Install Postgraphile as a library as per: https://postgraphile.org/postgraphile/next/quick-start-guide#install-postgraphile (ensure to use the Typescript files).
16
16
  Specifically, the `graphile.config.ts` and `pgl.ts`. If you need WebSocket support, make sure to add a plugin in `graphile.config.ts` as per: https://postgraphile.org/postgraphile/next/subscriptions
17
17
 
18
- 3. Enable WebSockets in `app.config.ts` if you need it:
18
+ 3. Install Headtart & URQL:
19
+ ```
20
+ yarn add @carvajalconsultants/headstart urql @urql/exchange-graphcache
21
+ ```
22
+
23
+ 4. Enable WebSockets in `app.config.ts` if you need it:
19
24
 
20
25
  ```
21
26
  // app.config.ts
@@ -30,7 +35,7 @@ export default defineConfig({
30
35
  });
31
36
  ```
32
37
 
33
- 4. Make sure to add the `/api` endpoint to the grafserv configuration so that Ruru GraphQL client works correctly:
38
+ 5. Make sure to add the `/api` endpoint to the grafserv configuration so that Ruru GraphQL client works correctly:
34
39
 
35
40
  ```
36
41
  // graphile.config.ts
@@ -45,21 +50,22 @@ const preset: GraphileConfig.Preset = {
45
50
  };
46
51
  ```
47
52
 
48
- 5. Add the api.ts file so that it calls our GraphQL handler. This will receive all GraphQL requests at the /api endpoint.
53
+ 6. Add the api.ts file so that it calls our GraphQL handler. This will receive all GraphQL requests at the /api endpoint.
49
54
 
50
55
  ```
51
56
  // app/api.ts
52
- import { createGraphQLRouteHandler } from "@carvajalconsultants/headstart/server";
57
+ import { defaultAPIFileRouteHandler } from "@tanstack/start/api";
58
+ import { createStartAPIHandler } from "@carvajalconsultants/headstart/server";
53
59
  import { pgl } from "../pgl";
54
60
 
55
- export default createGraphQLRouteHandler(pgl);
61
+ export default createStartAPIHandler(pgl, defaultAPIFileRouteHandler);
56
62
  ```
57
63
 
58
- 6. Now we need to configure URQL for client and server rendering, first we start with the server. Create this provider:
64
+ 7. Now we need to configure URQL for client and server rendering, first we start with the server. Create this provider:
59
65
 
60
66
  ```
61
67
  // app/graphql/serverProvider.tsx
62
- import { Client, Provider } from "urql";
68
+ import { Client } from "urql";
63
69
  import { grafastExchange } from "@carvajalconsultants/headstart/server";
64
70
  import { ssr } from "@carvajalconsultants/headstart/client";
65
71
  import { pgl } from "../../pgl";
@@ -75,7 +81,7 @@ export const client = new Client({
75
81
  });
76
82
  ```
77
83
 
78
- 7. Create the server side router which uses Grafast to execute queries:
84
+ 8. Create the server side router which uses Grafast to execute queries:
79
85
 
80
86
  ```
81
87
  // app/serverRouter.tsx
@@ -103,7 +109,7 @@ export function createRouter() {
103
109
  }
104
110
  ```
105
111
 
106
- 8. Modify the TSR server-side rendering function to use this new router:
112
+ 9. Modify the TSR server-side rendering function to use this new router:
107
113
 
108
114
  ```
109
115
  // app/ssr.tsx
@@ -122,7 +128,7 @@ export default createStartHandler({
122
128
  })(defaultStreamHandler);
123
129
  ```
124
130
 
125
- 9. Add the client side router which uses the fetch exchange to execute queries, mutations, etc.:
131
+ 10. Add the client side router which uses the fetch exchange to execute queries, mutations, etc.:
126
132
 
127
133
  ```
128
134
  // app/clientRouter.tsx
@@ -151,7 +157,7 @@ export function createRouter() {
151
157
  }
152
158
  ```
153
159
 
154
- 10. Tell TSR to use our client side router:
160
+ 11. Tell TSR to use our client side router:
155
161
 
156
162
  ```
157
163
  // app/client.tsx
@@ -162,11 +168,10 @@ import { createRouter } from "./clientRouter";
162
168
 
163
169
  const router = createRouter();
164
170
 
165
- // biome-ignore lint: Safe enough to assume root element will be there
166
171
  hydrateRoot(document.getElementById("root")!, <StartClient router={router} />);
167
172
  ```
168
173
 
169
- 11. Last but not least, you're ready to start using URQL on your components and pages. First we create the route using the loader option so we can pre-load data:
174
+ 12. Last but not least, you're ready to start using URQL on your components and pages. First we create the route using the loader option so we can pre-load data:
170
175
 
171
176
  ```
172
177
  export const Route = createFileRoute("/")({
@@ -183,7 +188,7 @@ export const Route = createFileRoute("/")({
183
188
  });
184
189
  ```
185
190
 
186
- 12. Now in your component, you can query with URQL as you normally would:
191
+ 13. Now in your component, you can query with URQL as you normally would:
187
192
 
188
193
  ```
189
194
  const Home = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carvajalconsultants/headstart",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Library to assist in integrating PostGraphile with Tanstack Start and URQL.",
5
5
  "license": "MIT",
6
6
  "author": "Miguel Carvajal <omar@carvajalonline.com>",
@@ -17,13 +17,13 @@
17
17
  "lint": "biome check --write"
18
18
  },
19
19
  "dependencies": {
20
- "@biomejs/biome": "^1.9.4",
21
20
  "@tanstack/start": "^1.100.0",
22
21
  "postgraphile": "^5.0.0-beta.37",
23
22
  "urql": "^4.2.1",
24
23
  "vinxi": "^0.5.2"
25
24
  },
26
25
  "devDependencies": {
26
+ "@biomejs/biome": "^1.9.4",
27
27
  "@types/ws": "^8.5.14",
28
28
  "typescript": "^5.7.3"
29
29
  }