@quilted/create 0.1.81 → 0.1.83

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.1.83
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b8b0e5e2`](https://github.com/lemonmade/quilt/commit/b8b0e5e2bac4192d8e6b17b93868acec8524c611) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix some more GraphQL template type issues
8
+
9
+ ## 0.1.82
10
+
11
+ ### Patch Changes
12
+
13
+ - [`c40bc1de`](https://github.com/lemonmade/quilt/commit/c40bc1deb3e3b48c30c881a4dd7bd98e2807a596) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix more GraphQL template issues
14
+
3
15
  ## 0.1.81
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.1.81",
4
+ "version": "0.1.83",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -4,11 +4,7 @@ import {HTML} from '@quilted/quilt/html';
4
4
  import {Routing, useRoutes} from '@quilted/quilt/navigate';
5
5
  import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
6
6
  import {type PropsWithChildren} from '@quilted/quilt/react/tools';
7
- import {
8
- GraphQLContext,
9
- createGraphQLHttpFetch,
10
- type GraphQLFetch,
11
- } from '@quilted/quilt/graphql';
7
+ import {GraphQLContext, type GraphQLFetch} from '@quilted/quilt/graphql';
12
8
 
13
9
  import {ReactQueryContext} from '@quilted/react-query';
14
10
  import {QueryClient} from '@tanstack/react-query';
@@ -25,7 +21,7 @@ import {
25
21
  } from './shared/context.ts';
26
22
 
27
23
  export interface AppProps extends AppContextType {
28
- fetchGraphQL?: GraphQLFetch;
24
+ fetchGraphQL: GraphQLFetch;
29
25
  }
30
26
 
31
27
  // The root component for your application. You will typically render any
@@ -61,16 +57,14 @@ function Routes() {
61
57
  // This component renders any app-wide context.
62
58
  function AppContext({
63
59
  children,
64
- fetchGraphQL: customFetchGraphQL,
60
+ fetchGraphQL,
65
61
  ...context
66
62
  }: PropsWithChildren<AppProps>) {
67
- const {fetchGraphQL, queryClient} = useMemo(() => {
63
+ const {queryClient} = useMemo(() => {
68
64
  return {
69
- fetchGraphQL:
70
- customFetchGraphQL ?? createGraphQLHttpFetch({url: '/api/graphql'}),
71
65
  queryClient: new QueryClient(),
72
66
  };
73
- }, [customFetchGraphQL]);
67
+ }, []);
74
68
 
75
69
  return (
76
70
  <GraphQLContext fetch={fetchGraphQL}>
@@ -1,8 +1,13 @@
1
1
  import '@quilted/quilt/globals';
2
+
2
3
  import {hydrateRoot} from 'react-dom/client';
4
+ import {createGraphQLFetchOverHTTP} from '@quilted/quilt/graphql';
3
5
 
4
6
  import {App} from './App.tsx';
5
7
 
6
8
  const element = document.querySelector('#app')!;
7
9
 
8
- hydrateRoot(element, <App />);
10
+ hydrateRoot(
11
+ element,
12
+ <App fetchGraphQL={createGraphQLFetchOverHTTP({url: '/api/graphql'})} />,
13
+ );
@@ -9,7 +9,9 @@ import startQuery from './StartQuery.graphql';
9
9
  describe('<Start />', () => {
10
10
  it('welcomes the user with their name', async () => {
11
11
  const name = 'Winston';
12
- const graphql = new GraphQLController([fillGraphQL(startQuery, {name})]);
12
+ const graphql = new GraphQLController([
13
+ fillGraphQL(startQuery, {me: {name}}),
14
+ ]);
13
15
 
14
16
  const start = await renderApp(<Start />, {graphql});
15
17
 
@@ -8,7 +8,7 @@ export default function Start() {
8
8
 
9
9
  return (
10
10
  <div className={styles.Start}>
11
- {data ? `Hello ${data.name}!` : 'Hello!'}
11
+ {data ? `Hello ${data.me.name}!` : 'Hello!'}
12
12
  </div>
13
13
  );
14
14
  }
@@ -1,3 +1,5 @@
1
1
  query Start {
2
- name
2
+ me {
3
+ name
4
+ }
3
5
  }
@@ -1,9 +1,13 @@
1
1
  import {graphql} from 'graphql';
2
+ import {
3
+ toGraphQLSource,
4
+ type GraphQLFetch,
5
+ type GraphQLResult,
6
+ } from '@quilted/quilt/graphql';
2
7
  import {
3
8
  createGraphQLSchema,
4
9
  createGraphQLResolverBuilder,
5
10
  } from '@quilted/quilt/graphql/server';
6
- import type {GraphQLResult, GraphQLSource} from '@quilted/quilt/graphql';
7
11
 
8
12
  import schemaSource, {type Schema} from '../graphql/schema.ts';
9
13
 
@@ -26,22 +30,13 @@ const Query = createQueryResolver({
26
30
 
27
31
  const schema = createGraphQLSchema(schemaSource, {Query, Person});
28
32
 
29
- export async function performGraphQLOperation<
30
- Data = Record<string, unknown>,
31
- Variables = Record<string, unknown>,
32
- >(
33
- operation: GraphQLSource<Data, Variables>,
34
- {
35
- variables,
36
- operationName,
37
- }: {variables?: Variables; operationName?: string} = {},
38
- ) {
39
- const result = await graphql({
40
- schema,
41
- source: operation,
42
- operationName,
43
- variableValues: variables,
44
- });
45
-
46
- return result as GraphQLResult<Data>;
47
- }
33
+ export const performGraphQLOperation: GraphQLFetch =
34
+ async function performGraphQLOperation(operation, options) {
35
+ const result = await graphql({
36
+ schema,
37
+ source: toGraphQLSource(operation),
38
+ variableValues: options?.variables as Readonly<{}>,
39
+ });
40
+
41
+ return result as GraphQLResult<any>;
42
+ };
@@ -1,7 +1,6 @@
1
1
  import '@quilted/quilt/globals';
2
2
 
3
3
  import {RequestRouter, JSONResponse} from '@quilted/quilt/request-router';
4
- import {type GraphQLFetch} from '@quilted/quilt/graphql';
5
4
  import {BrowserAssets} from '@quilted/quilt/magic/assets';
6
5
 
7
6
  const router = new RequestRouter();
@@ -29,23 +28,13 @@ router.get(async (request) => {
29
28
  import('@quilted/quilt/server'),
30
29
  ]);
31
30
 
32
- // GraphQL API, called during server rendering
33
- const fetchGraphQL: GraphQLFetch = async (operation, options) => {
34
- const result = await performGraphQLOperation<any>(
35
- (operation as any).source,
36
- {
37
- variables: options?.variables as any,
38
- operationName: (operation as any).name,
39
- },
40
- );
41
-
42
- return result;
43
- };
44
-
45
- const response = await renderToResponse(<App fetchGraphQL={fetchGraphQL} />, {
46
- request,
47
- assets,
48
- });
31
+ const response = await renderToResponse(
32
+ <App fetchGraphQL={performGraphQLOperation} />,
33
+ {
34
+ request,
35
+ assets,
36
+ },
37
+ );
49
38
 
50
39
  return response;
51
40
  });