@carvajalconsultants/headstart 1.0.0 → 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.
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,22 +50,24 @@ 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";
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";
63
- import { grafastExchange, ssr } from "@carvajalconsultants/headstart";
68
+ import { Client } from "urql";
69
+ import { grafastExchange } from "@carvajalconsultants/headstart/server";
70
+ import { ssr } from "@carvajalconsultants/headstart/client";
64
71
  import { pgl } from "../../pgl";
65
72
 
66
73
  /**
@@ -74,11 +81,11 @@ export const client = new Client({
74
81
  });
75
82
  ```
76
83
 
77
- 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:
78
85
 
79
86
  ```
80
87
  // app/serverRouter.tsx
81
- import { ssr } from "@carvajalconsultants/headstart";
88
+ import { ssr } from "@carvajalconsultants/headstart/client";
82
89
  import { createRouter as createTanStackRouter } from "@tanstack/react-router";
83
90
  import { Provider } from "urql";
84
91
  import { client } from "./graphql/serverProvider";
@@ -102,7 +109,7 @@ export function createRouter() {
102
109
  }
103
110
  ```
104
111
 
105
- 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:
106
113
 
107
114
  ```
108
115
  // app/ssr.tsx
@@ -121,11 +128,11 @@ export default createStartHandler({
121
128
  })(defaultStreamHandler);
122
129
  ```
123
130
 
124
- 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.:
125
132
 
126
133
  ```
127
134
  // app/clientRouter.tsx
128
- import { ssr } from "@carvajalconsultants/headstart";
135
+ import { ssr } from "@carvajalconsultants/headstart/client";
129
136
  import { createRouter as createTanStackRouter } from "@tanstack/react-router";
130
137
  import { Provider } from "urql";
131
138
  import { client } from "./graphql/clientProvider";
@@ -150,7 +157,7 @@ export function createRouter() {
150
157
  }
151
158
  ```
152
159
 
153
- 10. Tell TSR to use our client side router:
160
+ 11. Tell TSR to use our client side router:
154
161
 
155
162
  ```
156
163
  // app/client.tsx
@@ -161,11 +168,10 @@ import { createRouter } from "./clientRouter";
161
168
 
162
169
  const router = createRouter();
163
170
 
164
- // biome-ignore lint: Safe enough to assume root element will be there
165
171
  hydrateRoot(document.getElementById("root")!, <StartClient router={router} />);
166
172
  ```
167
173
 
168
- 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:
169
175
 
170
176
  ```
171
177
  export const Route = createFileRoute("/")({
@@ -182,7 +188,7 @@ export const Route = createFileRoute("/")({
182
188
  });
183
189
  ```
184
190
 
185
- 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:
186
192
 
187
193
  ```
188
194
  const Home = () => {
package/package.json CHANGED
@@ -1,26 +1,29 @@
1
1
  {
2
2
  "name": "@carvajalconsultants/headstart",
3
- "version": "1.0.0",
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>",
7
7
  "repository": "github:carvajalconsultants/headstart",
8
8
  "type": "module",
9
- "main": "src/index.ts",
9
+ "main": "server.ts",
10
10
  "files": [
11
- "src"
11
+ "client.ts",
12
+ "grafastExchange.ts",
13
+ "graphQLRouteHandler.ts",
14
+ "server.ts"
12
15
  ],
13
16
  "scripts": {
14
17
  "lint": "biome check --write"
15
18
  },
16
19
  "dependencies": {
17
- "@biomejs/biome": "^1.9.4",
18
20
  "@tanstack/start": "^1.100.0",
19
21
  "postgraphile": "^5.0.0-beta.37",
20
22
  "urql": "^4.2.1",
21
23
  "vinxi": "^0.5.2"
22
24
  },
23
25
  "devDependencies": {
26
+ "@biomejs/biome": "^1.9.4",
24
27
  "@types/ws": "^8.5.14",
25
28
  "typescript": "^5.7.3"
26
29
  }
@@ -1,3 +1,2 @@
1
1
  export * from "./graphQLRouteHandler";
2
2
  export * from "./grafastExchange";
3
- export * from "./ssrExchange";
File without changes
File without changes