Skip to content

Commit 876844e

Browse files
GraphQL Code Generator v3: client-preset (#8302)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 8a4ef64 commit 876844e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3028
-1505
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@graphql-codegen/cli": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@graphql-codegen/plugin-helpers@^2.6.2` ↗︎](https://www.npmjs.com/package/@graphql-codegen/plugin-helpers/v/2.6.2) (from `^2.7.1`, in `dependencies`)
6+
- Updated dependency [`@whatwg-node/fetch@^0.3.0` ↗︎](https://www.npmjs.com/package/@whatwg-node/fetch/v/0.3.0) (from `^0.4.0`, in `dependencies`)
7+
- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/cosmiconfig-typescript-loader/v/4.0.0) (from `^4.0.0`, in `dependencies`)
8+
- Added dependency [`@babel/generator@^7.18.13` ↗︎](https://www.npmjs.com/package/@babel/generator/v/7.18.13) (to `dependencies`)
9+
- Added dependency [`@babel/template@^7.18.10` ↗︎](https://www.npmjs.com/package/@babel/template/v/7.18.10) (to `dependencies`)
10+
- Added dependency [`@babel/types@^7.18.13` ↗︎](https://www.npmjs.com/package/@babel/types/v/7.18.13) (to `dependencies`)
11+
- Added dependency [`@graphql-codegen/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-codegen/client-preset/v/1.0.1) (to `dependencies`)

.changeset/orange-hornets-thank.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@graphql-codegen/gql-tag-operations': minor
3+
'@graphql-codegen/gql-tag-operations-preset': minor
4+
"@graphql-codegen/cli": minor
5+
'@graphql-codegen/client-preset': patch
6+
---
7+
8+
**`@graphql-codegen/gql-tag-operations` and `@graphql-codegen/gql-tag-operations-preset`**
9+
10+
Introduce a `gqlTagName` configuration option
11+
12+
-----
13+
14+
**`@graphql-codegen/client-preset`**
15+
16+
New preset for GraphQL Code Generator v3, more information on the RFC: https://github.com/dotansimha/graphql-code-generator/issues/8296
17+
18+
19+
-----
20+
21+
**`@graphql-codegen/cli`**
22+
23+
Update init wizard with 3.0 recommendations (`codegen.ts`, `client` preset)

dev-test/codegen.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ generates:
422422
schema: ./dev-test/gql-tag-operations/schema.graphql
423423
documents: './dev-test/gql-tag-operations/src/**/*.ts'
424424
preset: gql-tag-operations-preset
425+
./dev-test/gql-tag-operations/graphql:
426+
schema: ./dev-test/gql-tag-operations/schema.graphql
427+
documents: './dev-test/gql-tag-operations/src/**/*.ts'
428+
preset: client
425429
./dev-test/gql-tag-operations-urql/gql:
426430
schema: ./dev-test/gql-tag-operations-urql/schema.graphql
427431
documents: './dev-test/gql-tag-operations-urql/src/**/*.ts'

dev-test/gql-tag-operations-masking-star-wars/gql/gql.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-disable */
2-
import * as graphql from './graphql.js';
2+
import * as types from './graphql.js';
33
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
44

55
const documents = {
66
'\n query HeroDetailsWithFragment($episode: Episode) {\n hero(episode: $episode) {\n ...HeroDetails\n }\n }\n':
7-
graphql.HeroDetailsWithFragmentDocument,
7+
types.HeroDetailsWithFragmentDocument,
88
'\n fragment HeroDetails on Character {\n __typename\n name\n ... on Human {\n height\n }\n ... on Droid {\n primaryFunction\n }\n }\n':
9-
graphql.HeroDetailsFragmentDoc,
9+
types.HeroDetailsFragmentDoc,
1010
};
1111

1212
export function gql(

dev-test/gql-tag-operations-masking/gql/gql.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* eslint-disable */
2-
import * as graphql from './graphql.js';
2+
import * as types from './graphql.js';
33
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
44

55
const documents = {
66
'\n fragment TweetFragment on Tweet {\n id\n body\n ...TweetAuthorFragment\n }\n':
7-
graphql.TweetFragmentFragmentDoc,
7+
types.TweetFragmentFragmentDoc,
88
'\n fragment TweetAuthorFragment on Tweet {\n id\n author {\n id\n username\n }\n }\n':
9-
graphql.TweetAuthorFragmentFragmentDoc,
9+
types.TweetAuthorFragmentFragmentDoc,
1010
'\n fragment TweetsFragment on Query {\n Tweets {\n id\n ...TweetFragment\n }\n }\n':
11-
graphql.TweetsFragmentFragmentDoc,
12-
'\n query TweetAppQuery {\n ...TweetsFragment\n }\n': graphql.TweetAppQueryDocument,
11+
types.TweetsFragmentFragmentDoc,
12+
'\n query TweetAppQuery {\n ...TweetsFragment\n }\n': types.TweetAppQueryDocument,
1313
};
1414

1515
export function gql(

dev-test/gql-tag-operations/gql/gql.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable */
2-
import * as graphql from './graphql.js';
2+
import * as types from './graphql.js';
33
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
44

55
const documents = {
6-
'\n query Foo {\n Tweets {\n id\n }\n }\n': graphql.FooDocument,
7-
'\n fragment Lel on Tweet {\n id\n body\n }\n': graphql.LelFragmentDoc,
8-
'\n query Bar {\n Tweets {\n ...Lel\n }\n }\n': graphql.BarDocument,
6+
'\n query Foo {\n Tweets {\n id\n }\n }\n': types.FooDocument,
7+
'\n fragment Lel on Tweet {\n id\n body\n }\n': types.LelFragmentDoc,
8+
'\n query Bar {\n Tweets {\n ...Lel\n }\n }\n': types.BarDocument,
99
};
1010

1111
export function gql(
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
2+
3+
export type FragmentType<TDocumentType extends DocumentNode<any, any>> = TDocumentType extends DocumentNode<
4+
infer TType,
5+
any
6+
>
7+
? TType extends { ' $fragmentName': infer TKey }
8+
? TKey extends string
9+
? { ' $fragmentRefs': { [key in TKey]: TType } }
10+
: never
11+
: never
12+
: never;
13+
14+
// return non-nullable if `fragmentType` is non-nullable
15+
export function useFragment<TType>(
16+
_documentNode: DocumentNode<TType, any>,
17+
fragmentType: FragmentType<DocumentNode<TType, any>>
18+
): TType;
19+
// return nullable if `fragmentType` is nullable
20+
export function useFragment<TType>(
21+
_documentNode: DocumentNode<TType, any>,
22+
fragmentType: FragmentType<DocumentNode<TType, any>> | null | undefined
23+
): TType | null | undefined;
24+
// return array of non-nullable if `fragmentType` is array of non-nullable
25+
export function useFragment<TType>(
26+
_documentNode: DocumentNode<TType, any>,
27+
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>>
28+
): ReadonlyArray<TType>;
29+
// return array of nullable if `fragmentType` is array of nullable
30+
export function useFragment<TType>(
31+
_documentNode: DocumentNode<TType, any>,
32+
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
33+
): ReadonlyArray<TType> | null | undefined;
34+
export function useFragment<TType>(
35+
_documentNode: DocumentNode<TType, any>,
36+
fragmentType:
37+
| FragmentType<DocumentNode<TType, any>>
38+
| ReadonlyArray<FragmentType<DocumentNode<TType, any>>>
39+
| null
40+
| undefined
41+
): TType | ReadonlyArray<TType> | null | undefined {
42+
return fragmentType as any;
43+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable */
2+
import * as types from './graphql.js';
3+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
4+
5+
const documents = {
6+
'\n query Foo {\n Tweets {\n id\n }\n }\n': types.FooDocument,
7+
'\n fragment Lel on Tweet {\n id\n body\n }\n': types.LelFragmentDoc,
8+
'\n query Bar {\n Tweets {\n ...Lel\n }\n }\n': types.BarDocument,
9+
};
10+
11+
export function graphql(
12+
source: '\n query Foo {\n Tweets {\n id\n }\n }\n'
13+
): typeof documents['\n query Foo {\n Tweets {\n id\n }\n }\n'];
14+
export function graphql(
15+
source: '\n fragment Lel on Tweet {\n id\n body\n }\n'
16+
): typeof documents['\n fragment Lel on Tweet {\n id\n body\n }\n'];
17+
export function graphql(
18+
source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n'
19+
): typeof documents['\n query Bar {\n Tweets {\n ...Lel\n }\n }\n'];
20+
21+
export function graphql(source: string): unknown;
22+
export function graphql(source: string) {
23+
return (documents as any)[source] ?? {};
24+
}
25+
26+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<
27+
infer TType,
28+
any
29+
>
30+
? TType
31+
: never;
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/* eslint-disable */
2+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
3+
export type Maybe<T> = T | null;
4+
export type InputMaybe<T> = Maybe<T>;
5+
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
6+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
7+
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
8+
/** All built-in and custom scalars, mapped to their actual values */
9+
export type Scalars = {
10+
ID: string;
11+
String: string;
12+
Boolean: boolean;
13+
Int: number;
14+
Float: number;
15+
Date: any;
16+
Url: any;
17+
};
18+
19+
export type Meta = {
20+
__typename?: 'Meta';
21+
count?: Maybe<Scalars['Int']>;
22+
};
23+
24+
export type Mutation = {
25+
__typename?: 'Mutation';
26+
createTweet?: Maybe<Tweet>;
27+
deleteTweet?: Maybe<Tweet>;
28+
markTweetRead?: Maybe<Scalars['Boolean']>;
29+
};
30+
31+
export type MutationCreateTweetArgs = {
32+
body?: InputMaybe<Scalars['String']>;
33+
};
34+
35+
export type MutationDeleteTweetArgs = {
36+
id: Scalars['ID'];
37+
};
38+
39+
export type MutationMarkTweetReadArgs = {
40+
id: Scalars['ID'];
41+
};
42+
43+
export type Notification = {
44+
__typename?: 'Notification';
45+
date?: Maybe<Scalars['Date']>;
46+
id?: Maybe<Scalars['ID']>;
47+
type?: Maybe<Scalars['String']>;
48+
};
49+
50+
export type Query = {
51+
__typename?: 'Query';
52+
Notifications?: Maybe<Array<Maybe<Notification>>>;
53+
NotificationsMeta?: Maybe<Meta>;
54+
Tweet?: Maybe<Tweet>;
55+
Tweets?: Maybe<Array<Maybe<Tweet>>>;
56+
TweetsMeta?: Maybe<Meta>;
57+
User?: Maybe<User>;
58+
};
59+
60+
export type QueryNotificationsArgs = {
61+
limit?: InputMaybe<Scalars['Int']>;
62+
};
63+
64+
export type QueryTweetArgs = {
65+
id: Scalars['ID'];
66+
};
67+
68+
export type QueryTweetsArgs = {
69+
limit?: InputMaybe<Scalars['Int']>;
70+
skip?: InputMaybe<Scalars['Int']>;
71+
sort_field?: InputMaybe<Scalars['String']>;
72+
sort_order?: InputMaybe<Scalars['String']>;
73+
};
74+
75+
export type QueryUserArgs = {
76+
id: Scalars['ID'];
77+
};
78+
79+
export type Stat = {
80+
__typename?: 'Stat';
81+
likes?: Maybe<Scalars['Int']>;
82+
responses?: Maybe<Scalars['Int']>;
83+
retweets?: Maybe<Scalars['Int']>;
84+
views?: Maybe<Scalars['Int']>;
85+
};
86+
87+
export type Tweet = {
88+
__typename?: 'Tweet';
89+
Author?: Maybe<User>;
90+
Stats?: Maybe<Stat>;
91+
body?: Maybe<Scalars['String']>;
92+
date?: Maybe<Scalars['Date']>;
93+
id: Scalars['ID'];
94+
};
95+
96+
export type User = {
97+
__typename?: 'User';
98+
avatar_url?: Maybe<Scalars['Url']>;
99+
first_name?: Maybe<Scalars['String']>;
100+
full_name?: Maybe<Scalars['String']>;
101+
id: Scalars['ID'];
102+
last_name?: Maybe<Scalars['String']>;
103+
/** @deprecated Field no longer supported */
104+
name?: Maybe<Scalars['String']>;
105+
username?: Maybe<Scalars['String']>;
106+
};
107+
108+
export type FooQueryVariables = Exact<{ [key: string]: never }>;
109+
110+
export type FooQuery = { __typename?: 'Query'; Tweets?: Array<{ __typename?: 'Tweet'; id: string } | null> | null };
111+
112+
export type LelFragment = { __typename?: 'Tweet'; id: string; body?: string | null } & {
113+
' $fragmentName': 'LelFragment';
114+
};
115+
116+
export type BarQueryVariables = Exact<{ [key: string]: never }>;
117+
118+
export type BarQuery = {
119+
__typename?: 'Query';
120+
Tweets?: Array<({ __typename?: 'Tweet' } & { ' $fragmentRefs': { LelFragment: LelFragment } }) | null> | null;
121+
};
122+
123+
export const LelFragmentDoc = {
124+
kind: 'Document',
125+
definitions: [
126+
{
127+
kind: 'FragmentDefinition',
128+
name: { kind: 'Name', value: 'Lel' },
129+
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Tweet' } },
130+
selectionSet: {
131+
kind: 'SelectionSet',
132+
selections: [
133+
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
134+
{ kind: 'Field', name: { kind: 'Name', value: 'body' } },
135+
],
136+
},
137+
},
138+
],
139+
} as unknown as DocumentNode<LelFragment, unknown>;
140+
export const FooDocument = {
141+
kind: 'Document',
142+
definitions: [
143+
{
144+
kind: 'OperationDefinition',
145+
operation: 'query',
146+
name: { kind: 'Name', value: 'Foo' },
147+
selectionSet: {
148+
kind: 'SelectionSet',
149+
selections: [
150+
{
151+
kind: 'Field',
152+
name: { kind: 'Name', value: 'Tweets' },
153+
selectionSet: {
154+
kind: 'SelectionSet',
155+
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'id' } }],
156+
},
157+
},
158+
],
159+
},
160+
},
161+
],
162+
} as unknown as DocumentNode<FooQuery, FooQueryVariables>;
163+
export const BarDocument = {
164+
kind: 'Document',
165+
definitions: [
166+
{
167+
kind: 'OperationDefinition',
168+
operation: 'query',
169+
name: { kind: 'Name', value: 'Bar' },
170+
selectionSet: {
171+
kind: 'SelectionSet',
172+
selections: [
173+
{
174+
kind: 'Field',
175+
name: { kind: 'Name', value: 'Tweets' },
176+
selectionSet: {
177+
kind: 'SelectionSet',
178+
selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'Lel' } }],
179+
},
180+
},
181+
],
182+
},
183+
},
184+
...LelFragmentDoc.definitions,
185+
],
186+
} as unknown as DocumentNode<BarQuery, BarQueryVariables>;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './gql.js';
2+
export * from './fragment-masking.js';

0 commit comments

Comments
 (0)