Skip to content

Commit 2c5e428

Browse files
committed
Migrate typescript-graphql-apollo to Vitest
1 parent 5d2792c commit 2c5e428

5 files changed

Lines changed: 96 additions & 74 deletions

File tree

packages/plugins/typescript/graphql-apollo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"graphql-tag": "^2.0.0"
4242
},
4343
"dependencies": {
44-
"@graphql-codegen/plugin-helpers": "^3.0.0",
45-
"@graphql-codegen/visitor-plugin-common": "^2.12.1",
44+
"@graphql-codegen/plugin-helpers": "^6.0.0",
45+
"@graphql-codegen/visitor-plugin-common": "^6.0.0",
4646
"auto-bind": "~4.0.0",
4747
"change-case-all": "1.0.15",
4848
"tslib": "^2.8.1"

packages/plugins/typescript/graphql-apollo/tests/__snapshots__/graphql-apollo.spec.ts.snap

Lines changed: 75 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`apollo-client sdk Should generate Sdk correctly 1`] = `
3+
exports[`apollo-client > sdk > Should generate Sdk correctly 1`] = `
44
"export type Maybe<T> = T | null;
55
export type InputMaybe<T> = Maybe<T>;
66
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
77
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
88
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
9+
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
10+
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
911
import { ApolloClient, QueryOptions, SubscriptionOptions, MutationOptions } from '@apollo/client';
1012
import gql from 'graphql-tag';
1113
/** All built-in and custom scalars, mapped to their actual values */
1214
export type Scalars = {
13-
ID: string;
14-
String: string;
15-
Boolean: boolean;
16-
Int: number;
17-
Float: number;
15+
ID: { input: string; output: string; }
16+
String: { input: string; output: string; }
17+
Boolean: { input: boolean; output: boolean; }
18+
Int: { input: number; output: number; }
19+
Float: { input: number; output: number; }
1820
};
1921
2022
export type Query = {
@@ -30,13 +32,13 @@ export type Query = {
3032
3133
export type QueryFeedArgs = {
3234
type: FeedType;
33-
offset?: InputMaybe<Scalars['Int']>;
34-
limit?: InputMaybe<Scalars['Int']>;
35+
offset?: InputMaybe<Scalars['Int']['input']>;
36+
limit?: InputMaybe<Scalars['Int']['input']>;
3537
};
3638
3739
3840
export type QueryEntryArgs = {
39-
repoFullName: Scalars['String'];
41+
repoFullName: Scalars['String']['input'];
4042
};
4143
4244
/** A list of options for the sort order of the feed */
@@ -57,26 +59,26 @@ export type Entry = {
5759
/** The GitHub user who submitted this entry */
5860
postedBy: User;
5961
/** A timestamp of when the entry was submitted */
60-
createdAt: Scalars['Float'];
62+
createdAt: Scalars['Float']['output'];
6163
/** The score of this repository, upvotes - downvotes */
62-
score: Scalars['Int'];
64+
score: Scalars['Int']['output'];
6365
/** The hot score of this repository */
64-
hotScore: Scalars['Float'];
66+
hotScore: Scalars['Float']['output'];
6567
/** Comments posted about this repository */
6668
comments: Array<Maybe<Comment>>;
6769
/** The number of comments posted about this repository */
68-
commentCount: Scalars['Int'];
70+
commentCount: Scalars['Int']['output'];
6971
/** The SQL ID of this entry */
70-
id: Scalars['Int'];
72+
id: Scalars['Int']['output'];
7173
/** XXX to be changed */
7274
vote: Vote;
7375
};
7476
7577
7678
/** Information about a GitHub repository submitted to GitHunt */
7779
export type EntryCommentsArgs = {
78-
limit?: InputMaybe<Scalars['Int']>;
79-
offset?: InputMaybe<Scalars['Int']>;
80+
limit?: InputMaybe<Scalars['Int']['input']>;
81+
offset?: InputMaybe<Scalars['Int']['input']>;
8082
};
8183
8284
/**
@@ -86,17 +88,17 @@ export type EntryCommentsArgs = {
8688
export type Repository = {
8789
__typename?: 'Repository';
8890
/** Just the name of the repository, e.g. GitHunt-API */
89-
name: Scalars['String'];
91+
name: Scalars['String']['output'];
9092
/** The full name of the repository with the username, e.g. apollostack/GitHunt-API */
91-
full_name: Scalars['String'];
93+
full_name: Scalars['String']['output'];
9294
/** The description of the repository */
93-
description?: Maybe<Scalars['String']>;
95+
description?: Maybe<Scalars['String']['output']>;
9496
/** The link to the repository on GitHub */
95-
html_url: Scalars['String'];
97+
html_url: Scalars['String']['output'];
9698
/** The number of people who have starred this repository on GitHub */
97-
stargazers_count: Scalars['Int'];
99+
stargazers_count: Scalars['Int']['output'];
98100
/** The number of open issues on this repository on GitHub */
99-
open_issues_count?: Maybe<Scalars['Int']>;
101+
open_issues_count?: Maybe<Scalars['Int']['output']>;
100102
/** The owner of this repository on GitHub, e.g. apollostack */
101103
owner?: Maybe<User>;
102104
};
@@ -105,32 +107,32 @@ export type Repository = {
105107
export type User = {
106108
__typename?: 'User';
107109
/** The name of the user, e.g. apollostack */
108-
login: Scalars['String'];
110+
login: Scalars['String']['output'];
109111
/** The URL to a directly embeddable image for this user's avatar */
110-
avatar_url: Scalars['String'];
112+
avatar_url: Scalars['String']['output'];
111113
/** The URL of this user's GitHub page */
112-
html_url: Scalars['String'];
114+
html_url: Scalars['String']['output'];
113115
};
114116
115117
/** A comment about an entry, submitted by a user */
116118
export type Comment = {
117119
__typename?: 'Comment';
118120
/** The SQL ID of this entry */
119-
id: Scalars['Int'];
121+
id: Scalars['Int']['output'];
120122
/** The GitHub user who posted the comment */
121123
postedBy: User;
122124
/** A timestamp of when the comment was posted */
123-
createdAt: Scalars['Float'];
125+
createdAt: Scalars['Float']['output'];
124126
/** The text of the comment */
125-
content: Scalars['String'];
127+
content: Scalars['String']['output'];
126128
/** The repository which this comment is about */
127-
repoName: Scalars['String'];
129+
repoName: Scalars['String']['output'];
128130
};
129131
130132
/** XXX to be removed */
131133
export type Vote = {
132134
__typename?: 'Vote';
133-
vote_value: Scalars['Int'];
135+
vote_value: Scalars['Int']['output'];
134136
};
135137
136138
export type Mutation = {
@@ -145,19 +147,19 @@ export type Mutation = {
145147
146148
147149
export type MutationSubmitRepositoryArgs = {
148-
repoFullName: Scalars['String'];
150+
repoFullName: Scalars['String']['input'];
149151
};
150152
151153
152154
export type MutationVoteArgs = {
153-
repoFullName: Scalars['String'];
155+
repoFullName: Scalars['String']['input'];
154156
type: VoteType;
155157
};
156158
157159
158160
export type MutationSubmitCommentArgs = {
159-
repoFullName: Scalars['String'];
160-
commentContent: Scalars['String'];
161+
repoFullName: Scalars['String']['input'];
162+
commentContent: Scalars['String']['input'];
161163
};
162164
163165
/** The type of vote to record, when submitting a vote */
@@ -175,7 +177,7 @@ export type Subscription = {
175177
176178
177179
export type SubscriptionCommentAddedArgs = {
178-
repoFullName: Scalars['String'];
180+
repoFullName: Scalars['String']['input'];
179181
};
180182
export type FeedQueryVariables = Exact<{ [key: string]: never; }>;
181183
@@ -306,21 +308,23 @@ async function test() {
306308
}"
307309
`;
308310
309-
exports[`apollo-client sdk Should support useTypeImports 1`] = `
311+
exports[`apollo-client > sdk > Should support useTypeImports 1`] = `
310312
"export type Maybe<T> = T | null;
311313
export type InputMaybe<T> = Maybe<T>;
312314
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
313315
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
314316
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
317+
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
318+
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
315319
import type { ApolloClient, QueryOptions, SubscriptionOptions, MutationOptions } from '@apollo/client';
316320
import gql from 'graphql-tag';
317321
/** All built-in and custom scalars, mapped to their actual values */
318322
export type Scalars = {
319-
ID: string;
320-
String: string;
321-
Boolean: boolean;
322-
Int: number;
323-
Float: number;
323+
ID: { input: string; output: string; }
324+
String: { input: string; output: string; }
325+
Boolean: { input: boolean; output: boolean; }
326+
Int: { input: number; output: number; }
327+
Float: { input: number; output: number; }
324328
};
325329
326330
export type Query = {
@@ -336,13 +340,13 @@ export type Query = {
336340
337341
export type QueryFeedArgs = {
338342
type: FeedType;
339-
offset?: InputMaybe<Scalars['Int']>;
340-
limit?: InputMaybe<Scalars['Int']>;
343+
offset?: InputMaybe<Scalars['Int']['input']>;
344+
limit?: InputMaybe<Scalars['Int']['input']>;
341345
};
342346
343347
344348
export type QueryEntryArgs = {
345-
repoFullName: Scalars['String'];
349+
repoFullName: Scalars['String']['input'];
346350
};
347351
348352
/** A list of options for the sort order of the feed */
@@ -363,26 +367,26 @@ export type Entry = {
363367
/** The GitHub user who submitted this entry */
364368
postedBy: User;
365369
/** A timestamp of when the entry was submitted */
366-
createdAt: Scalars['Float'];
370+
createdAt: Scalars['Float']['output'];
367371
/** The score of this repository, upvotes - downvotes */
368-
score: Scalars['Int'];
372+
score: Scalars['Int']['output'];
369373
/** The hot score of this repository */
370-
hotScore: Scalars['Float'];
374+
hotScore: Scalars['Float']['output'];
371375
/** Comments posted about this repository */
372376
comments: Array<Maybe<Comment>>;
373377
/** The number of comments posted about this repository */
374-
commentCount: Scalars['Int'];
378+
commentCount: Scalars['Int']['output'];
375379
/** The SQL ID of this entry */
376-
id: Scalars['Int'];
380+
id: Scalars['Int']['output'];
377381
/** XXX to be changed */
378382
vote: Vote;
379383
};
380384
381385
382386
/** Information about a GitHub repository submitted to GitHunt */
383387
export type EntryCommentsArgs = {
384-
limit?: InputMaybe<Scalars['Int']>;
385-
offset?: InputMaybe<Scalars['Int']>;
388+
limit?: InputMaybe<Scalars['Int']['input']>;
389+
offset?: InputMaybe<Scalars['Int']['input']>;
386390
};
387391
388392
/**
@@ -392,17 +396,17 @@ export type EntryCommentsArgs = {
392396
export type Repository = {
393397
__typename?: 'Repository';
394398
/** Just the name of the repository, e.g. GitHunt-API */
395-
name: Scalars['String'];
399+
name: Scalars['String']['output'];
396400
/** The full name of the repository with the username, e.g. apollostack/GitHunt-API */
397-
full_name: Scalars['String'];
401+
full_name: Scalars['String']['output'];
398402
/** The description of the repository */
399-
description?: Maybe<Scalars['String']>;
403+
description?: Maybe<Scalars['String']['output']>;
400404
/** The link to the repository on GitHub */
401-
html_url: Scalars['String'];
405+
html_url: Scalars['String']['output'];
402406
/** The number of people who have starred this repository on GitHub */
403-
stargazers_count: Scalars['Int'];
407+
stargazers_count: Scalars['Int']['output'];
404408
/** The number of open issues on this repository on GitHub */
405-
open_issues_count?: Maybe<Scalars['Int']>;
409+
open_issues_count?: Maybe<Scalars['Int']['output']>;
406410
/** The owner of this repository on GitHub, e.g. apollostack */
407411
owner?: Maybe<User>;
408412
};
@@ -411,32 +415,32 @@ export type Repository = {
411415
export type User = {
412416
__typename?: 'User';
413417
/** The name of the user, e.g. apollostack */
414-
login: Scalars['String'];
418+
login: Scalars['String']['output'];
415419
/** The URL to a directly embeddable image for this user's avatar */
416-
avatar_url: Scalars['String'];
420+
avatar_url: Scalars['String']['output'];
417421
/** The URL of this user's GitHub page */
418-
html_url: Scalars['String'];
422+
html_url: Scalars['String']['output'];
419423
};
420424
421425
/** A comment about an entry, submitted by a user */
422426
export type Comment = {
423427
__typename?: 'Comment';
424428
/** The SQL ID of this entry */
425-
id: Scalars['Int'];
429+
id: Scalars['Int']['output'];
426430
/** The GitHub user who posted the comment */
427431
postedBy: User;
428432
/** A timestamp of when the comment was posted */
429-
createdAt: Scalars['Float'];
433+
createdAt: Scalars['Float']['output'];
430434
/** The text of the comment */
431-
content: Scalars['String'];
435+
content: Scalars['String']['output'];
432436
/** The repository which this comment is about */
433-
repoName: Scalars['String'];
437+
repoName: Scalars['String']['output'];
434438
};
435439
436440
/** XXX to be removed */
437441
export type Vote = {
438442
__typename?: 'Vote';
439-
vote_value: Scalars['Int'];
443+
vote_value: Scalars['Int']['output'];
440444
};
441445
442446
export type Mutation = {
@@ -451,19 +455,19 @@ export type Mutation = {
451455
452456
453457
export type MutationSubmitRepositoryArgs = {
454-
repoFullName: Scalars['String'];
458+
repoFullName: Scalars['String']['input'];
455459
};
456460
457461
458462
export type MutationVoteArgs = {
459-
repoFullName: Scalars['String'];
463+
repoFullName: Scalars['String']['input'];
460464
type: VoteType;
461465
};
462466
463467
464468
export type MutationSubmitCommentArgs = {
465-
repoFullName: Scalars['String'];
466-
commentContent: Scalars['String'];
469+
repoFullName: Scalars['String']['input'];
470+
commentContent: Scalars['String']['input'];
467471
};
468472
469473
/** The type of vote to record, when submitting a vote */
@@ -481,7 +485,7 @@ export type Subscription = {
481485
482486
483487
export type SubscriptionCommentAddedArgs = {
484-
repoFullName: Scalars['String'];
488+
repoFullName: Scalars['String']['input'];
485489
};
486490
export type FeedQueryVariables = Exact<{ [key: string]: never; }>;
487491
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineProject, mergeConfig } from 'vitest/config';
2+
import { sharedConfig } from '../../../../vitest.config.js';
3+
4+
export default mergeConfig(
5+
sharedConfig,
6+
defineProject({
7+
test: {
8+
name: 'typescript-graphql-apollo',
9+
include: ['**/*.spec.ts'],
10+
setupFiles: './vitest.setup.ts',
11+
},
12+
}),
13+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createRequire } from 'node:module';
2+
3+
// Inject it into the global scope so dependencies can see it
4+
// This is a hack since `@graphql-codegen/testing`'s `validateTs` was written for CJS
5+
globalThis.require = createRequire(import.meta.url);

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@
16021602
auto-bind "~4.0.0"
16031603
tslib "~2.6.0"
16041604

1605-
"@graphql-codegen/[email protected]", "@graphql-codegen/visitor-plugin-common@^2.12.1":
1605+
"@graphql-codegen/[email protected]":
16061606
version "2.13.8"
16071607
resolved "https://registry.yarnpkg.com/@graphql-codegen/visitor-plugin-common/-/visitor-plugin-common-2.13.8.tgz#09bc6317b227e5a278f394f4cef0d6c2d1910597"
16081608
integrity sha512-IQWu99YV4wt8hGxIbBQPtqRuaWZhkQRG2IZKbMoSvh0vGeWb3dB0n0hSgKaOOxDY+tljtOf9MTcUYvJslQucMQ==

0 commit comments

Comments
 (0)