@quilted/create 0.2.25 → 0.2.27

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @quilted/create
2
2
 
3
+ ## 0.2.27
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e5877f9`](https://github.com/lemonmade/quilt/commit/e5877f9b94f62a8ec09a75a44f028c4530ea9f2d) Thanks [@lemonmade](https://github.com/lemonmade)! - Update GraphQL template
8
+
9
+ ## 0.2.26
10
+
11
+ ### Patch Changes
12
+
13
+ - [`5c32e10`](https://github.com/lemonmade/quilt/commit/5c32e1022e5330a209817f7bfb49b09b301b36b7) Thanks [@lemonmade](https://github.com/lemonmade)! - Expose app context on browser console in template apps
14
+
3
15
  ## 0.2.25
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quilted/create",
3
3
  "type": "module",
4
- "version": "0.2.25",
4
+ "version": "0.2.27",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -2,14 +2,20 @@ import '@quilted/quilt/globals';
2
2
  import {hydrate} from 'preact';
3
3
  import {Browser, BrowserContext} from '@quilted/quilt/browser';
4
4
 
5
+ import type {AppContext} from '~/shared/context.ts';
5
6
  import {App} from './App.tsx';
6
7
 
7
8
  const element = document.querySelector('#app')!;
8
9
  const browser = new Browser();
9
10
 
11
+ const context = {} satisfies AppContext;
12
+
13
+ // Makes key parts of the app available in the browser console
14
+ Object.assign(globalThis, {app: context});
15
+
10
16
  hydrate(
11
17
  <BrowserContext browser={browser}>
12
- <App />
18
+ <App context={context} />
13
19
  </BrowserContext>,
14
20
  element,
15
21
  );
@@ -1,7 +1,12 @@
1
1
  import type {RenderableProps} from 'preact';
2
+ import {Suspense} from 'preact/compat';
2
3
 
3
4
  import styles from './Frame.module.css';
4
5
 
5
6
  export function Frame({children}: RenderableProps<{}>) {
6
- return <div className={styles.Frame}>{children}</div>;
7
+ return (
8
+ <div className={styles.Frame}>
9
+ <Suspense fallback={null}>{children}</Suspense>
10
+ </div>
11
+ );
7
12
  }
@@ -1,10 +1,9 @@
1
1
  import type {RenderableProps} from 'preact';
2
2
 
3
+ import {AsyncContext} from '@quilted/quilt/async';
4
+ import {GraphQLContext} from '@quilted/quilt/graphql';
3
5
  import {Routing, useRoutes} from '@quilted/quilt/navigate';
4
6
  import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
5
- import {GraphQLContext} from '@quilted/quilt/graphql';
6
-
7
- import {ReactQueryContext} from '@quilted/react-query';
8
7
 
9
8
  import {HTML} from './foundation/html.ts';
10
9
  import {Frame} from './foundation/frame.ts';
@@ -51,11 +50,11 @@ function AppContext({children, context}: RenderableProps<AppProps>) {
51
50
  return (
52
51
  <AppContextReact.Provider value={context}>
53
52
  <GraphQLContext fetch={context.fetchGraphQL}>
54
- <ReactQueryContext client={context.queryClient}>
53
+ <AsyncContext cache={context.asyncCache}>
55
54
  <Localization locale={locale}>
56
55
  <Routing>{children}</Routing>
57
56
  </Localization>
58
- </ReactQueryContext>
57
+ </AsyncContext>
59
58
  </GraphQLContext>
60
59
  </AppContextReact.Provider>
61
60
  );
@@ -1,21 +1,31 @@
1
1
  import '@quilted/quilt/globals';
2
2
 
3
3
  import {hydrate} from 'preact';
4
- import {QueryClient} from '@tanstack/react-query';
4
+ import {AsyncActionCache} from '@quilted/quilt/async';
5
5
  import {createGraphQLFetch} from '@quilted/quilt/graphql';
6
6
  import {Browser, BrowserContext} from '@quilted/quilt/browser';
7
7
 
8
+ import type {AppContext} from '~/shared/context.ts';
9
+
8
10
  import {App} from './App.tsx';
9
11
 
10
12
  const element = document.querySelector('#app')!;
11
13
  const browser = new Browser();
12
14
 
13
- const queryClient = new QueryClient();
14
15
  const fetchGraphQL = createGraphQLFetch({url: '/api/graphql'});
16
+ const asyncCache = new AsyncActionCache();
17
+
18
+ const context = {
19
+ fetchGraphQL,
20
+ asyncCache,
21
+ } satisfies AppContext;
22
+
23
+ // Makes key parts of the app available in the browser console
24
+ Object.assign(globalThis, {app: context});
15
25
 
16
26
  hydrate(
17
27
  <BrowserContext browser={browser}>
18
- <App context={{fetchGraphQL, queryClient}} />
28
+ <App context={context} />
19
29
  </BrowserContext>,
20
30
  element,
21
31
  );
@@ -1,14 +1,13 @@
1
- import {useGraphQLQuery} from '@quilted/react-query';
1
+ import {useGraphQLQuery} from '@quilted/quilt/graphql';
2
2
 
3
3
  import styles from './Start.module.css';
4
4
  import startQuery from './StartQuery.graphql';
5
5
 
6
6
  export default function Start() {
7
- const {data} = useGraphQLQuery(startQuery);
7
+ const query = useGraphQLQuery(startQuery);
8
8
 
9
- return (
10
- <div className={styles.Start}>
11
- {data ? `Hello ${data.me.name}!` : 'Hello!'}
12
- </div>
13
- );
9
+ const me = query.result?.data?.me;
10
+ const greeting = me ? `Hello ${me.name}!` : 'Hello!';
11
+
12
+ return <div className={styles.Start}>{greeting}</div>;
14
13
  }
@@ -1,7 +1,12 @@
1
1
  import type {RenderableProps} from 'preact';
2
+ import {Suspense} from 'preact/compat';
2
3
 
3
4
  import styles from './Frame.module.css';
4
5
 
5
6
  export function Frame({children}: RenderableProps<{}>) {
6
- return <div className={styles.Frame}>{children}</div>;
7
+ return (
8
+ <div className={styles.Frame}>
9
+ <Suspense fallback={null}>{children}</Suspense>
10
+ </div>
11
+ );
7
12
  }
@@ -13,8 +13,6 @@
13
13
  "devDependencies": {
14
14
  "@quilted/graphql-tools": "^0.2.0",
15
15
  "@quilted/quilt": "^0.7.0",
16
- "@quilted/react-query": "^0.4.0",
17
- "@tanstack/react-query": "^5.0.0",
18
16
  "graphql": "^16.8.0",
19
17
  "jsdom": "^24.0.0",
20
18
  "preact": "^10.21.0",
@@ -21,19 +21,23 @@ router.post('/api/graphql', async (request) => {
21
21
 
22
22
  // For all GET requests, render our React application.
23
23
  router.get(async (request) => {
24
- const [{App}, {performGraphQLOperation}, {renderToResponse}, {QueryClient}] =
25
- await Promise.all([
26
- import('./App.tsx'),
27
- import('./server/graphql.ts'),
28
- import('@quilted/quilt/server'),
29
- import('@tanstack/react-query'),
30
- ]);
24
+ const [
25
+ {App},
26
+ {performGraphQLOperation},
27
+ {renderToResponse},
28
+ {AsyncActionCache},
29
+ ] = await Promise.all([
30
+ import('./App.tsx'),
31
+ import('./server/graphql.ts'),
32
+ import('@quilted/quilt/server'),
33
+ import('@quilted/quilt/async'),
34
+ ]);
31
35
 
32
36
  const response = await renderToResponse(
33
37
  <App
34
38
  context={{
35
39
  fetchGraphQL: performGraphQLOperation,
36
- queryClient: new QueryClient(),
40
+ asyncCache: new AsyncActionCache(),
37
41
  }}
38
42
  />,
39
43
  {
@@ -1,10 +1,10 @@
1
1
  import type {GraphQLFetch} from '@quilted/quilt/graphql';
2
- import type {QueryClient} from '@tanstack/react-query';
2
+ import type {AsyncActionCache} from '@quilted/quilt/async';
3
3
 
4
4
  declare module '~/shared/context.ts' {
5
5
  interface AppContext {
6
- queryClient: QueryClient;
7
- fetchGraphQL: GraphQLFetch<{}>;
6
+ readonly fetchGraphQL: GraphQLFetch;
7
+ readonly asyncCache: AsyncActionCache;
8
8
  }
9
9
  }
10
10
 
@@ -1,9 +1,10 @@
1
+ import {Suspense} from 'preact/compat';
2
+
1
3
  import {createRender} from '@quilted/quilt/testing';
2
4
  import {BrowserContext, BrowserTestMock} from '@quilted/quilt/browser/testing';
3
5
  import {TestRouting, TestRouter} from '@quilted/quilt/navigate/testing';
4
6
  import {Localization} from '@quilted/quilt/localize';
5
-
6
- import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
7
+ import {AsyncActionCache, AsyncContext} from '@quilted/quilt/async';
7
8
 
8
9
  import {AppContextReact} from '~/shared/context.ts';
9
10
 
@@ -28,18 +29,19 @@ export const renderApp = createRender<
28
29
  router = new TestRouter(),
29
30
  browser = new BrowserTestMock(),
30
31
  graphql = new GraphQLController(),
32
+ asyncCache = new AsyncActionCache(),
31
33
  }) {
32
34
  return {
33
35
  router,
34
36
  browser,
35
37
  graphql,
36
38
  fetchGraphQL: graphql.fetch,
37
- queryClient: new QueryClient(),
39
+ asyncCache,
38
40
  };
39
41
  },
40
42
  // Render all of our app-wide context providers around each component under test.
41
43
  render(element, context, {locale = 'en'}) {
42
- const {router, browser, graphql, queryClient} = context;
44
+ const {router, browser, graphql, asyncCache} = context;
43
45
 
44
46
  return (
45
47
  <AppContextReact.Provider value={context}>
@@ -47,9 +49,9 @@ export const renderApp = createRender<
47
49
  <Localization locale={locale}>
48
50
  <TestRouting router={router}>
49
51
  <GraphQLTesting controller={graphql}>
50
- <QueryClientProvider client={queryClient}>
51
- {element}
52
- </QueryClientProvider>
52
+ <AsyncContext cache={asyncCache}>
53
+ <Suspense fallback={null}>{element}</Suspense>
54
+ </AsyncContext>
53
55
  </GraphQLTesting>
54
56
  </TestRouting>
55
57
  </Localization>
@@ -65,9 +67,6 @@ export const renderApp = createRender<
65
67
 
66
68
  await wrapper.act(async () => {
67
69
  await wrapper.context.graphql.resolveAll();
68
-
69
- // react-query needs an extra tick to set state in response to GraphQL queries.
70
- await new Promise((resolve) => setTimeout(resolve, 0));
71
70
  });
72
71
  },
73
72
  });
@@ -1,6 +1,6 @@
1
1
  import type {TestRouter} from '@quilted/quilt/navigate/testing';
2
2
  import type {BrowserTestMock} from '@quilted/quilt/browser/testing';
3
- import type {QueryClient} from '@tanstack/react-query';
3
+ import type {AsyncActionCache} from '@quilted/quilt/async';
4
4
 
5
5
  import type {AppContext} from '~/shared/context.ts';
6
6
 
@@ -42,6 +42,12 @@ export interface RenderOptions {
42
42
  */
43
43
  readonly graphql?: GraphQLController;
44
44
 
45
+ /**
46
+ * The cache of GraphQL query results. When not provided, an empty cache
47
+ * will be used.
48
+ */
49
+ readonly asyncCache?: AsyncActionCache;
50
+
45
51
  /**
46
52
  * A custom locale to use for this component test.
47
53
  */
@@ -65,9 +71,9 @@ export interface RenderContext extends AppContext {
65
71
  readonly graphql: GraphQLController;
66
72
 
67
73
  /**
68
- * The react-query client used for this component test.
74
+ * The cache of GraphQL query results.
69
75
  */
70
- readonly queryClient: QueryClient;
76
+ readonly asyncCache: AsyncActionCache;
71
77
  }
72
78
 
73
79
  export interface RenderActions extends Record<string, never> {}
@@ -5,6 +5,7 @@ import {httpBatchLink} from '@trpc/client';
5
5
  import {QueryClient} from '@tanstack/react-query';
6
6
  import {Browser, BrowserContext} from '@quilted/quilt/browser';
7
7
 
8
+ import type {AppContext} from '~/shared/context.ts';
8
9
  import {trpc} from '~/shared/trpc.ts';
9
10
 
10
11
  import {App} from './App.tsx';
@@ -17,9 +18,17 @@ const trpcClient = trpc.createClient({
17
18
  links: [httpBatchLink({url: new URL('/api', window.location.href).href})],
18
19
  });
19
20
 
21
+ const context = {
22
+ trpc: trpcClient,
23
+ queryClient,
24
+ } satisfies AppContext;
25
+
26
+ // Makes key parts of the app available in the browser console
27
+ Object.assign(globalThis, {app: context});
28
+
20
29
  hydrate(
21
30
  <BrowserContext browser={browser}>
22
- <App context={{trpc: trpcClient, queryClient}} />
31
+ <App context={context} />
23
32
  </BrowserContext>,
24
33
  element,
25
34
  );
@@ -1,7 +1,12 @@
1
1
  import type {RenderableProps} from 'preact';
2
+ import {Suspense} from 'preact/compat';
2
3
 
3
4
  import styles from './Frame.module.css';
4
5
 
5
6
  export function Frame({children}: RenderableProps<{}>) {
6
- return <div className={styles.Frame}>{children}</div>;
7
+ return (
8
+ <div className={styles.Frame}>
9
+ <Suspense fallback={null}>{children}</Suspense>
10
+ </div>
11
+ );
7
12
  }