@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 +12 -0
- package/package.json +1 -1
- package/templates/app-basic/browser.tsx +7 -1
- package/templates/app-basic/foundation/frame/Frame.tsx +6 -1
- package/templates/app-graphql/App.tsx +4 -5
- package/templates/app-graphql/browser.tsx +13 -3
- package/templates/app-graphql/features/start/Start/Start.tsx +6 -7
- package/templates/app-graphql/foundation/frame/Frame.tsx +6 -1
- package/templates/app-graphql/package.json +0 -2
- package/templates/app-graphql/server.tsx +12 -8
- package/templates/app-graphql/shared/graphql.ts +3 -3
- package/templates/app-graphql/tests/render/render.tsx +9 -10
- package/templates/app-graphql/tests/render/types.ts +9 -3
- package/templates/app-trpc/browser.tsx +10 -1
- package/templates/app-trpc/foundation/frame/Frame.tsx +6 -1
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
|
@@ -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
|
|
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
|
-
<
|
|
53
|
+
<AsyncContext cache={context.asyncCache}>
|
|
55
54
|
<Localization locale={locale}>
|
|
56
55
|
<Routing>{children}</Routing>
|
|
57
56
|
</Localization>
|
|
58
|
-
</
|
|
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 {
|
|
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={
|
|
28
|
+
<App context={context} />
|
|
19
29
|
</BrowserContext>,
|
|
20
30
|
element,
|
|
21
31
|
);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {useGraphQLQuery} from '@quilted/
|
|
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
|
|
7
|
+
const query = useGraphQLQuery(startQuery);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
7
|
+
return (
|
|
8
|
+
<div className={styles.Frame}>
|
|
9
|
+
<Suspense fallback={null}>{children}</Suspense>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
7
12
|
}
|
|
@@ -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 [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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 {
|
|
2
|
+
import type {AsyncActionCache} from '@quilted/quilt/async';
|
|
3
3
|
|
|
4
4
|
declare module '~/shared/context.ts' {
|
|
5
5
|
interface AppContext {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
-
<
|
|
51
|
-
{element}
|
|
52
|
-
</
|
|
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 {
|
|
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
|
|
74
|
+
* The cache of GraphQL query results.
|
|
69
75
|
*/
|
|
70
|
-
readonly
|
|
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={
|
|
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
|
|
7
|
+
return (
|
|
8
|
+
<div className={styles.Frame}>
|
|
9
|
+
<Suspense fallback={null}>{children}</Suspense>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
7
12
|
}
|