Skip to content

Commit 219e6c6

Browse files
committed
Cleanup after rebase
1 parent 6a2738b commit 219e6c6

31 files changed

+418
-207
lines changed

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ packages/presets/swc-plugin/tests/fixtures
3434
# Ignore intentional error files
3535
packages/graphql-codegen-cli/tests/test-files/schema-dir/error-schema.graphql
3636
packages/graphql-codegen-cli/tests/test-files/error-document.graphql
37+
38+
# Ignore dev-tests with no prettier requirement
39+
dev-test/test-schema/flow-types.flow.js
40+
dev-test-apollo-tooling/src/__generated__/

dev-test-apollo-tooling/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
The `dev-test-apollo-tooling` package is an example of migrating from Apollo tooling to GraphQL Codegen. It attempts to generate output as close as possible to Apollo tooling’s output. Note: **this package is a work in progress** and currently requires a patch to `near-operation-file`. We will fix this package soon.
1+
The `dev-test-apollo-tooling` package is an example of migrating from Apollo tooling to GraphQL
2+
Codegen. It attempts to generate output as close as possible to Apollo tooling’s output. Note:
3+
**this package is a work in progress** and currently requires a patch to `near-operation-file`. We
4+
will fix this package soon.
25

36
How to run this package:
47

5-
1. Make sure you have the correct Yarn version installed (check the root package.json, `packageManager` entry). Otherwise, you might run into unexplained bugs.
8+
1. Make sure you have the correct Yarn version installed (check the root package.json,
9+
`packageManager` entry). Otherwise, you might run into unexplained bugs.
610
2. In the monorepo root, run:
711

812
yarn clean && yarn install && yarn build
913

10-
3. Patch `near-operation-file` manually (the automatic patch doesn’t always work). In the monorepo root, run:
14+
3. Patch `near-operation-file` manually (the automatic patch doesn’t always work). In the monorepo
15+
root, run:
1116

1217
yarn postinstall
1318

1419
4. Go to the `dev-test-apollo-tooling` directory and run:
1520

16-
cd dev-test-apollo-tooling
17-
yarn install
18-
yarn start
21+
cd dev-test-apollo-tooling yarn install yarn start
1922

2023
This will generate type files in `dev-test-apollo-tooling/src/__generated__/*`.

dev-test-apollo-tooling/cli/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env ts-node
2-
32
import { generate } from '@graphql-codegen/cli';
43
import type { Types } from '@graphql-codegen/plugin-helpers';
54

@@ -62,7 +61,10 @@ export const main = async () => {
6261

6362
await generate({
6463
schema: localSchemaFilePath,
65-
documents: [...includes.map((include: any) => `${include}/**/*.{js,jsx,ts,tsx}`), `!**/${GENERATED}/**`],
64+
documents: [
65+
...includes.map((include: any) => `${include}/**/*.{js,jsx,ts,tsx}`),
66+
`!**/${GENERATED}/**`,
67+
],
6668
config: GRAPHQL_CODEGEN_CONFIG,
6769
generates: generatePaths,
6870
silent: false,
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
22
"name": "dev-test-apollo-tooling",
3-
"private": true,
4-
"description": "A setup which mimics Apollo tooling generation as close as possible",
53
"version": "0.0.1",
64
"type": "module",
5+
"description": "A setup which mimics Apollo tooling generation as close as possible",
6+
"private": true,
7+
"files": [
8+
"cli"
9+
],
10+
"scripts": {
11+
"start": "tsx cli/index.ts",
12+
"start:debug": "NODE_OPTIONS='--trace-warnings' tsx cli/index.ts",
13+
"start:verbose": "DEBUG='*' tsx cli/index.ts",
14+
"test": "vitest --no-watch"
15+
},
716
"dependencies": {
817
"@apollo/client": "3.13.8",
918
"@graphql-codegen/cli": "*",
1019
"@graphql-codegen/plugin-helpers": "*",
20+
"@graphql-codegen/typed-document-node": "*",
1121
"@graphql-codegen/typescript-operations": "*",
12-
"@graphql-codegen/visitor-plugin-common": "*",
13-
"@graphql-codegen/typed-document-node": "*"
22+
"@graphql-codegen/visitor-plugin-common": "*"
1423
},
1524
"devDependencies": {
1625
"@types/node": "^25.0.3",
1726
"tsx": "4.7.0",
1827
"typescript": "^5.9.3",
1928
"vitest": "4.0.4"
2029
},
21-
"files": [
22-
"cli"
23-
],
24-
"scripts": {
25-
"start": "tsx cli/index.ts",
26-
"start:debug": "NODE_OPTIONS='--trace-warnings' tsx cli/index.ts",
27-
"start:verbose": "DEBUG='*' tsx cli/index.ts",
28-
"test": "vitest --no-watch"
29-
},
3030
"sideEffects": false
3131
}

dev-test-apollo-tooling/schema.graphql

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ directive @join__field(
2020
overrideLabel: String
2121
) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
2222

23-
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
23+
directive @join__implements(
24+
graph: join__Graph!
25+
interface: String!
26+
) repeatable on OBJECT | INTERFACE
2427

2528
directive @join__type(
2629
graph: join__Graph!
@@ -32,7 +35,12 @@ directive @join__type(
3235

3336
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
3437

35-
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
38+
directive @link(
39+
url: String
40+
as: String
41+
for: link__Purpose
42+
import: [link__Import]
43+
) repeatable on SCHEMA
3644

3745
directive @tag(
3846
name: String!
@@ -47,10 +55,15 @@ enum link__Purpose {
4755
}
4856

4957
enum join__Graph {
50-
SUPER_USER_MANAGER @join__graph(name: "super_user_management", url: "http://i.am.not.used.example.com")
51-
GRAPHQL_MAIN__SHARD__BASE @join__graph(name: "graphql_main__shard__base", url: "http://i.am.not.used.example.com")
58+
SUPER_USER_MANAGER
59+
@join__graph(name: "super_user_management", url: "http://i.am.not.used.example.com")
60+
GRAPHQL_MAIN__SHARD__BASE
61+
@join__graph(name: "graphql_main__shard__base", url: "http://i.am.not.used.example.com")
5262
GRAPHQL_MAIN__SHARD__INTERNAL_TESTING
53-
@join__graph(name: "graphql_main__shard__internal_testing", url: "http://i.am.not.used.example.com")
63+
@join__graph(
64+
name: "graphql_main__shard__internal_testing"
65+
url: "http://i.am.not.used.example.com"
66+
)
5467
}
5568

5669
type Query {
@@ -203,8 +216,12 @@ enum ProcessableFeedbackSortBy
203216
enum ProcessableFeedbackSortOrder
204217
@join__type(graph: GRAPHQL_MAIN__SHARD__BASE)
205218
@join__type(graph: GRAPHQL_MAIN__SHARD__INTERNAL_TESTING) {
206-
ASC @join__enumValue(graph: GRAPHQL_MAIN__SHARD__BASE) @join__enumValue(graph: GRAPHQL_MAIN__SHARD__INTERNAL_TESTING)
207-
DESC @join__enumValue(graph: GRAPHQL_MAIN__SHARD__BASE) @join__enumValue(graph: GRAPHQL_MAIN__SHARD__INTERNAL_TESTING)
219+
ASC
220+
@join__enumValue(graph: GRAPHQL_MAIN__SHARD__BASE)
221+
@join__enumValue(graph: GRAPHQL_MAIN__SHARD__INTERNAL_TESTING)
222+
DESC
223+
@join__enumValue(graph: GRAPHQL_MAIN__SHARD__BASE)
224+
@join__enumValue(graph: GRAPHQL_MAIN__SHARD__INTERNAL_TESTING)
208225
}
209226

210227
type FeedbackConnection @join__type(graph: GRAPHQL_MAIN__SHARD__BASE) {
@@ -229,7 +246,8 @@ type Thread implements Node
229246
@join__implements(graph: GRAPHQL_MAIN__SHARD__BASE, interface: "Node")
230247
@join__type(graph: GRAPHQL_MAIN__SHARD__BASE) {
231248
id: ID!
232-
posts(after: String, first: Int): ThreadPostConnection @join__field(graph: GRAPHQL_MAIN__SHARD__BASE)
249+
posts(after: String, first: Int): ThreadPostConnection
250+
@join__field(graph: GRAPHQL_MAIN__SHARD__BASE)
233251
}
234252

235253
type ThreadPostConnection @join__type(graph: GRAPHQL_MAIN__SHARD__BASE) {
@@ -253,7 +271,7 @@ union ThreadPostCreator
253271
@join__type(graph: GRAPHQL_MAIN__SHARD__BASE)
254272
@join__unionMember(graph: GRAPHQL_MAIN__SHARD__BASE, member: "OrgMember")
255273
@join__unionMember(graph: GRAPHQL_MAIN__SHARD__BASE, member: "EndUser") =
256-
OrgMember
274+
| OrgMember
257275
| EndUser
258276

259277
type OrgMember @join__type(graph: GRAPHQL_MAIN__SHARD__BASE) {

dev-test-apollo-tooling/src/Component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Check that `UserManagerRoleType` enum is generated in `__generated__/Component.ts`
44
*/
55

6-
import { useQuery, gql } from '@apollo/client';
6+
import { gql, useQuery } from '@apollo/client';
77
import Helper from './Helper';
88

99
export const getFooQuery = gql`

dev-test-apollo-tooling/tests/Component.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { describe, it, expect } from 'vitest';
21
import { readFileSync } from 'node:fs';
3-
import { fileURLToPath } from 'node:url';
42
import { dirname, join } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { describe, expect, it } from 'vitest';
55

66
const __dirname = dirname(fileURLToPath(import.meta.url));
77

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { describe, it, expect } from 'vitest';
21
import { readFileSync } from 'node:fs';
3-
import { fileURLToPath } from 'node:url';
42
import { dirname, join } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { describe, expect, it } from 'vitest';
55

66
const __dirname = dirname(fileURLToPath(import.meta.url));
77

88
describe('Duplicates.ts', () => {
99
it('ConfigTypeDefinitions types should be exported', () => {
10-
const fileContent = readFileSync(join(__dirname, '../src/__generated__/Duplicates.ts'), 'utf-8');
10+
const fileContent = readFileSync(
11+
join(__dirname, '../src/__generated__/Duplicates.ts'),
12+
'utf-8',
13+
);
1114

1215
expect(fileContent).toMatch(/export type ConfigTypeDefinitions_ConfigActionId\s*=/);
1316
expect(fileContent).toMatch(/export type ConfigTypeDefinitions_ConfigEnum\s*=/);
@@ -16,16 +19,19 @@ describe('Duplicates.ts', () => {
1619
});
1720

1821
it('GetFeedbackData creator union type exports should exist', () => {
19-
const fileContent = readFileSync(join(__dirname, '../src/__generated__/Duplicates.ts'), 'utf-8');
22+
const fileContent = readFileSync(
23+
join(__dirname, '../src/__generated__/Duplicates.ts'),
24+
'utf-8',
25+
);
2026

2127
expect(fileContent).toMatch(
22-
/export type GetFeedbackData_organization_internalOrgData_processableFeedback_edges_node_orgMemberThread_posts_edges_node_creator\s*=/
28+
/export type GetFeedbackData_organization_internalOrgData_processableFeedback_edges_node_orgMemberThread_posts_edges_node_creator\s*=/,
2329
);
2430
expect(fileContent).toMatch(
25-
/export type GetFeedbackData_organization_internalOrgData_processableFeedback_edges_node_orgMemberThread_posts_edges_node_creator_EndUser\s*=/
31+
/export type GetFeedbackData_organization_internalOrgData_processableFeedback_edges_node_orgMemberThread_posts_edges_node_creator_EndUser\s*=/,
2632
);
2733
expect(fileContent).toMatch(
28-
/export type GetFeedbackData_organization_internalOrgData_processableFeedback_edges_node_orgMemberThread_posts_edges_node_creator_OrgMember\s*=/
34+
/export type GetFeedbackData_organization_internalOrgData_processableFeedback_edges_node_orgMemberThread_posts_edges_node_creator_OrgMember\s*=/,
2935
);
3036
});
3137
});

dev-test-apollo-tooling/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export default mergeConfig(
88
name: 'dev-test-apollo-tooling',
99
include: ['tests/**/*.spec.ts', 'tests/**/*.test.ts'],
1010
},
11-
})
11+
}),
1212
);

dev-test/test-schema/flow-types.flow.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// @flow
22

33
import { type GraphQLResolveInfo } from 'graphql';
4-
export type $RequireFields<Origin, Keys> = $Diff<Origin, Keys> &
5-
$ObjMapi<Keys, <Key>(k: Key) => $NonMaybeType<$ElementType<Origin, Key>>>;
4+
export type $RequireFields<Origin, Keys> = $Diff<Origin, Keys> & $ObjMapi<Keys, <Key>(k: Key) => $NonMaybeType<$ElementType<Origin, Key>>>;
65
/** All built-in and custom scalars, mapped to their actual values */
76
export type Scalars = {|
87
ID: string,
@@ -18,6 +17,7 @@ export type Query = {|
1817
userById?: ?User,
1918
|};
2019

20+
2121
export type QueryUserByIdArgs = {|
2222
id: $ElementType<Scalars, 'Int'>,
2323
|};
@@ -33,21 +33,21 @@ export type Resolver<Result, Parent = {}, Context = {}, Args = {}> = (
3333
parent: Parent,
3434
args: Args,
3535
context: Context,
36-
info: GraphQLResolveInfo,
36+
info: GraphQLResolveInfo
3737
) => Promise<Result> | Result;
3838

3939
export type SubscriptionSubscribeFn<Result, Parent, Context, Args> = (
4040
parent: Parent,
4141
args: Args,
4242
context: Context,
43-
info: GraphQLResolveInfo,
43+
info: GraphQLResolveInfo
4444
) => AsyncIterator<Result> | Promise<AsyncIterator<Result>>;
4545

4646
export type SubscriptionResolveFn<Result, Parent, Context, Args> = (
4747
parent: Parent,
4848
args: Args,
4949
context: Context,
50-
info: GraphQLResolveInfo,
50+
info: GraphQLResolveInfo
5151
) => Result | Promise<Result>;
5252

5353
export interface SubscriptionSubscriberObject<Result, Key: string, Parent, Context, Args> {
@@ -71,14 +71,10 @@ export type SubscriptionResolver<Result, Key: string, Parent = {}, Context = {},
7171
export type TypeResolveFn<Types, Parent = {}, Context = {}> = (
7272
parent: Parent,
7373
context: Context,
74-
info: GraphQLResolveInfo,
74+
info: GraphQLResolveInfo
7575
) => ?Types | Promise<?Types>;
7676

77-
export type IsTypeOfResolverFn<T = {}, Context = {}> = (
78-
obj: T,
79-
context: Context,
80-
info: GraphQLResolveInfo,
81-
) => boolean | Promise<boolean>;
77+
export type IsTypeOfResolverFn<T = {}, Context = {}> = (obj: T, context: Context, info: GraphQLResolveInfo) => boolean | Promise<boolean>;
8278

8379
export type NextResolverFn<T> = () => Promise<T>;
8480

@@ -87,7 +83,7 @@ export type DirectiveResolverFn<Result = {}, Parent = {}, Args = {}, Context = {
8783
parent: Parent,
8884
args: Args,
8985
context: Context,
90-
info: GraphQLResolveInfo,
86+
info: GraphQLResolveInfo
9187
) => Result | Promise<Result>;
9288

9389
export type ResolverTypeWrapper<T> = Promise<T> | T;
@@ -110,23 +106,12 @@ export type ResolversParentTypes = {
110106
User: User,
111107
};
112108

113-
export type QueryResolvers<
114-
ContextType = any,
115-
ParentType = $ElementType<ResolversParentTypes, 'Query'>,
116-
> = {
109+
export type QueryResolvers<ContextType = any, ParentType = $ElementType<ResolversParentTypes, 'Query'>> = {
117110
allUsers?: Resolver<Array<?$ElementType<ResolversTypes, 'User'>>, ParentType, ContextType>,
118-
userById?: Resolver<
119-
?$ElementType<ResolversTypes, 'User'>,
120-
ParentType,
121-
ContextType,
122-
$RequireFields<QueryUserByIdArgs, { id: * }>,
123-
>,
111+
userById?: Resolver<?$ElementType<ResolversTypes, 'User'>, ParentType, ContextType, $RequireFields<QueryUserByIdArgs, { id: * }>>,
124112
};
125113

126-
export type UserResolvers<
127-
ContextType = any,
128-
ParentType = $ElementType<ResolversParentTypes, 'User'>,
129-
> = {
114+
export type UserResolvers<ContextType = any, ParentType = $ElementType<ResolversParentTypes, 'User'>> = {
130115
email?: Resolver<$ElementType<ResolversTypes, 'String'>, ParentType, ContextType>,
131116
id?: Resolver<$ElementType<ResolversTypes, 'Int'>, ParentType, ContextType>,
132117
name?: Resolver<$ElementType<ResolversTypes, 'String'>, ParentType, ContextType>,
@@ -137,3 +122,4 @@ export type Resolvers<ContextType = any> = {
137122
Query?: QueryResolvers<ContextType>,
138123
User?: UserResolvers<ContextType>,
139124
};
125+

0 commit comments

Comments
 (0)