Skip to content

Commit 5c0b123

Browse files
committed
refactor(codegen): remove dead maxFieldDepth code and enforce trailing commas
1 parent fd0f8e2 commit 5c0b123

94 files changed

Lines changed: 6196 additions & 3575 deletions

File tree

Some content is hidden

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

graphql/codegen/src/__tests__/codegen/__snapshots__/client-generator.test.ts.snap

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ exports[`client-generator generateOrmClientFile generates OrmClient class with e
107107
import type {
108108
GraphQLAdapter,
109109
GraphQLError,
110-
QueryResult
110+
QueryResult,
111111
} from '@constructive-io/graphql-types';
112112
113113
export type {
114114
GraphQLAdapter,
115115
GraphQLError,
116-
QueryResult
116+
QueryResult,
117117
} from '@constructive-io/graphql-types';
118118
119119
/**
@@ -125,33 +125,35 @@ export class FetchAdapter implements GraphQLAdapter {
125125
126126
constructor(
127127
private endpoint: string,
128-
headers?: Record<string, string>
128+
headers?: Record<string, string>,
129129
) {
130130
this.headers = headers ?? {};
131131
}
132132
133133
async execute<T>(
134134
document: string,
135-
variables?: Record<string, unknown>
135+
variables?: Record<string, unknown>,
136136
): Promise<QueryResult<T>> {
137137
const response = await fetch(this.endpoint, {
138138
method: 'POST',
139139
headers: {
140140
'Content-Type': 'application/json',
141141
Accept: 'application/json',
142-
...this.headers
142+
...this.headers,
143143
},
144144
body: JSON.stringify({
145145
query: document,
146-
variables: variables ?? {}
147-
})
146+
variables: variables ?? {},
147+
}),
148148
});
149149
150150
if (!response.ok) {
151151
return {
152152
ok: false,
153153
data: null,
154-
errors: [{ message: \`HTTP \${response.status}: \${response.statusText}\` }]
154+
errors: [
155+
{ message: \`HTTP \${response.status}: \${response.statusText}\` },
156+
],
155157
};
156158
}
157159
@@ -164,14 +166,14 @@ export class FetchAdapter implements GraphQLAdapter {
164166
return {
165167
ok: false,
166168
data: null,
167-
errors: json.errors
169+
errors: json.errors,
168170
};
169171
}
170172
171173
return {
172174
ok: true,
173175
data: json.data as T,
174-
errors: undefined
176+
errors: undefined,
175177
};
176178
}
177179
@@ -204,7 +206,7 @@ export interface OrmClientConfig {
204206
export class GraphQLRequestError extends Error {
205207
constructor(
206208
public readonly errors: GraphQLError[],
207-
public readonly data: unknown = null
209+
public readonly data: unknown = null,
208210
) {
209211
const messages = errors.map((e) => e.message).join('; ');
210212
super(\`GraphQL Error: \${messages}\`);
@@ -222,14 +224,14 @@ export class OrmClient {
222224
this.adapter = new FetchAdapter(config.endpoint, config.headers);
223225
} else {
224226
throw new Error(
225-
'OrmClientConfig requires either an endpoint or a custom adapter'
227+
'OrmClientConfig requires either an endpoint or a custom adapter',
226228
);
227229
}
228230
}
229231
230232
async execute<T>(
231233
document: string,
232-
variables?: Record<string, unknown>
234+
variables?: Record<string, unknown>,
233235
): Promise<QueryResult<T>> {
234236
return this.adapter.execute<T>(document, variables);
235237
}
@@ -304,7 +306,7 @@ export interface UpdateArgs<TSelect, TWhere, TData> {
304306
export type FindOneArgs<
305307
TSelect,
306308
TIdName extends string = 'id',
307-
TId = string
309+
TId = string,
308310
> = {
309311
select?: TSelect;
310312
} & Record<TIdName, TId>;
@@ -337,9 +339,13 @@ export type DeepExact<T, Shape> = T extends Shape
337339
? {
338340
[K in keyof T]: K extends keyof Shape
339341
? T[K] extends { select: infer NS }
340-
? Extract<Shape[K], { select?: unknown }> extends { select?: infer ShapeNS }
342+
? Extract<Shape[K], { select?: unknown }> extends {
343+
select?: infer ShapeNS;
344+
}
341345
? DeepExact<
342-
Omit<T[K], 'select'> & { select: DeepExact<NS, NonNullable<ShapeNS>> },
346+
Omit<T[K], 'select'> & {
347+
select: DeepExact<NS, NonNullable<ShapeNS>>;
348+
},
343349
Extract<Shape[K], { select?: unknown }>
344350
>
345351
: never

graphql/codegen/src/__tests__/codegen/client-generator.test.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,40 @@ import {
77
generateCreateClientFile,
88
generateOrmClientFile,
99
generateQueryBuilderFile,
10-
generateSelectTypesFile
10+
generateSelectTypesFile,
1111
} from '../../core/codegen/orm/client-generator';
12-
import type { CleanFieldType, CleanRelations,CleanTable } from '../../types/schema';
12+
import type {
13+
CleanFieldType,
14+
CleanRelations,
15+
CleanTable,
16+
} from '../../types/schema';
1317

1418
// ============================================================================
1519
// Test Fixtures
1620
// ============================================================================
1721

1822
const fieldTypes = {
1923
uuid: { gqlType: 'UUID', isArray: false } as CleanFieldType,
20-
string: { gqlType: 'String', isArray: false } as CleanFieldType
24+
string: { gqlType: 'String', isArray: false } as CleanFieldType,
2125
};
2226

2327
const emptyRelations: CleanRelations = {
2428
belongsTo: [],
2529
hasOne: [],
2630
hasMany: [],
27-
manyToMany: []
31+
manyToMany: [],
2832
};
2933

30-
function createTable(partial: Partial<CleanTable> & { name: string }): CleanTable {
34+
function createTable(
35+
partial: Partial<CleanTable> & { name: string },
36+
): CleanTable {
3137
return {
3238
name: partial.name,
3339
fields: partial.fields ?? [],
3440
relations: partial.relations ?? emptyRelations,
3541
query: partial.query,
3642
inflection: partial.inflection,
37-
constraints: partial.constraints
43+
constraints: partial.constraints,
3844
};
3945
}
4046

@@ -91,13 +97,25 @@ describe('client-generator', () => {
9197
createTable({
9298
name: 'User',
9399
fields: [{ name: 'id', type: fieldTypes.uuid }],
94-
query: { all: 'users', one: 'user', create: 'createUser', update: 'updateUser', delete: 'deleteUser' }
100+
query: {
101+
all: 'users',
102+
one: 'user',
103+
create: 'createUser',
104+
update: 'updateUser',
105+
delete: 'deleteUser',
106+
},
95107
}),
96108
createTable({
97109
name: 'Post',
98110
fields: [{ name: 'id', type: fieldTypes.uuid }],
99-
query: { all: 'posts', one: 'post', create: 'createPost', update: 'updatePost', delete: 'deletePost' }
100-
})
111+
query: {
112+
all: 'posts',
113+
one: 'post',
114+
create: 'createPost',
115+
update: 'updatePost',
116+
delete: 'deletePost',
117+
},
118+
}),
101119
];
102120

103121
const result = generateCreateClientFile(tables, false, false);
@@ -114,8 +132,14 @@ describe('client-generator', () => {
114132
createTable({
115133
name: 'User',
116134
fields: [{ name: 'id', type: fieldTypes.uuid }],
117-
query: { all: 'users', one: 'user', create: 'createUser', update: 'updateUser', delete: 'deleteUser' }
118-
})
135+
query: {
136+
all: 'users',
137+
one: 'user',
138+
create: 'createUser',
139+
update: 'updateUser',
140+
delete: 'deleteUser',
141+
},
142+
}),
119143
];
120144

121145
const result = generateCreateClientFile(tables, true, true);
@@ -124,7 +148,9 @@ describe('client-generator', () => {
124148
expect(result.content).toContain('createQueryOperations');
125149
expect(result.content).toContain('createMutationOperations');
126150
expect(result.content).toContain('query: createQueryOperations(client)');
127-
expect(result.content).toContain('mutation: createMutationOperations(client)');
151+
expect(result.content).toContain(
152+
'mutation: createMutationOperations(client)',
153+
);
128154
});
129155
});
130156
});

0 commit comments

Comments
 (0)