Skip to content

Commit 5f1a037

Browse files
authored
Support @oneOf on input objects (#131)
1 parent 6456220 commit 5f1a037

File tree

21 files changed

+5882
-5217
lines changed

21 files changed

+5882
-5217
lines changed

.changeset/few-icons-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ts-gql/compiler": patch
3+
---
4+
5+
Add support for `@oneOf` on input objects. Note this is dependent on having a version of `graphql` that supports `@oneOf` as well.

.github/actions/ci-setup/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ runs:
44
steps:
55
- uses: actions/checkout@v2
66

7+
- run: npm i -g [email protected]
8+
shell: bash
9+
710
- name: Enable Corepack
811
run: corepack enable
912
shell: bash
1013

11-
- name: Use Node.js 16
14+
- name: Use Node.js 22
1215
uses: actions/setup-node@v2
1316
with:
14-
node-version: 16
17+
node-version: 22
1518
cache: "pnpm"
1619

1720
- name: Install Dependencies

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"editor.codeActionsOnSave": {
3-
"source.fixAll.eslint": true
3+
"source.fixAll.eslint": "explicit"
44
}
55
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"private": true,
66
"repository": "https://github.com/Thinkmill/ts-gql",
77
"license": "MIT",
8-
"packageManager": "pnpm@7.14.2",
8+
"packageManager": "pnpm@9.15.5",
99
"engines": {
10-
"pnpm": "7.14.2"
10+
"pnpm": "9.15.5"
1111
},
1212
"dependencies": {
1313
"@babel/core": "^7.19.3",
@@ -21,12 +21,13 @@
2121
"@preconstruct/cli": "^2.8.3",
2222
"@ts-gql/eslint-plugin": "*",
2323
"@types/jest": "^29.1.2",
24+
"@types/node": "^22.13.1",
2425
"@typescript-eslint/eslint-plugin": "^5.40.0",
2526
"@typescript-eslint/parser": "^6.3.0",
2627
"babel-jest": "^29.1.2",
2728
"babel-plugin-macros": "^3.1.0",
2829
"eslint": "^8.25.0",
29-
"graphql": "^16.3.0",
30+
"graphql": "^16.10.0",
3031
"jest": "^29.1.2",
3132
"prettier": "^2.7.1",
3233
"typescript": "^5.1.6"

packages/apollo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"devDependencies": {
2323
"@apollo/client": "^3.6.9",
24-
"graphql": "^16.3.0",
24+
"graphql": "^16.10.0",
2525
"react": "^16.14.0"
2626
},
2727
"repository": "https://github.com/Thinkmill/ts-gql/tree/main/packages/apollo"

packages/compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@types/babel__code-frame": "^7.0.1",
4545
"@types/graceful-fs": "^4.1.3",
4646
"fixturez": "^1.1.0",
47-
"graphql": "^16.3.0",
47+
"graphql": "^16.10.0",
4848
"lazy-require.macro": "^0.1.0",
4949
"tempy": "1.0.1"
5050
},

packages/compiler/src/inline-fragments.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function removeUnnecessaryFragmentSpreads(
8686
const { TypeInfo } = typeInfoExports;
8787
const visitorExports =
8888
lazyRequire<typeof import("graphql/language/visitor")>();
89-
const visitWithTypeInfo: typeof typeInfoExports["visitWithTypeInfo"] =
89+
const visitWithTypeInfo: (typeof typeInfoExports)["visitWithTypeInfo"] =
9090
typeInfoExports.visitWithTypeInfo ||
9191
(visitorExports as any).visitWithTypeInfo;
9292

packages/compiler/src/schema-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export async function cachedGenerateSchemaTypes(config: Config) {
7878
config.schemaHash +
7979
JSON.stringify(config.scalars) +
8080
config.readonlyTypes +
81-
"v3"
81+
"v4"
8282
);
8383
let types: string;
8484
let filename = path.join(

packages/compiler/src/schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ function printInputObjectType(
155155
type: GraphQLInputObjectType,
156156
options: InternalPrinterOptions
157157
) {
158+
if (type.isOneOf) {
159+
return `export type ${type.name} = {\n${Object.values(type.getFields())
160+
.map((field) =>
161+
printInputFields(
162+
[{ ...field, type: new GraphQLNonNull(field.type) }],
163+
options
164+
)
165+
)
166+
.join("\n} | {\n")}\n};`;
167+
}
158168
return `export type ${type.name} = {\n${printInputFields(
159169
Object.values(type.getFields()),
160170
options

packages/compiler/src/test/__snapshots__/index.test.ts.snap

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ exports[`basic 1`] = `
55
"errors": [],
66
"fsOperations": [
77
{
8-
"content": "// ts-gql-integrity:f6ea04fc77a35de27cc60303681c1fa7
8+
"content": "// ts-gql-integrity:997632f649b7de9f77dd86807bf02a84
99
/*
1010
ts-gql-meta-begin
1111
{
12-
"hash": "4675d6839380c78593be64c208a1e269"
12+
"hash": "bf8896f7a97d11c70f4c40e769886c9a"
1313
}
1414
ts-gql-meta-end
1515
*/
@@ -52,11 +52,11 @@ exports[`list with fragment works as expected 1`] = `
5252
"errors": [],
5353
"fsOperations": [
5454
{
55-
"content": "// ts-gql-integrity:ba99aa0d6c3af78b52fdbf7adce11c1b
55+
"content": "// ts-gql-integrity:13b0b74c1f8d6b697f98466cb54fa627
5656
/*
5757
ts-gql-meta-begin
5858
{
59-
"hash": "c470e5d9c42f47ab5e54e0429804e41a"
59+
"hash": "f37365cb606682e37f67ccf1b557235a"
6060
}
6161
ts-gql-meta-end
6262
*/
@@ -88,11 +88,11 @@ export const document = JSON.parse("{\\"kind\\":\\"Document\\",\\"definitions\\"
8888
"type": "output",
8989
},
9090
{
91-
"content": "// ts-gql-integrity:8bf558becbcb56e3fb34c7e3c7a3f2fc
91+
"content": "// ts-gql-integrity:df098928fb170e7869a4a8cc9cfe76f4
9292
/*
9393
ts-gql-meta-begin
9494
{
95-
"hash": "fab3f2252c12683e11363909e642b618"
95+
"hash": "b84b1868541bafdb7b7119be30ea5bd9"
9696
}
9797
ts-gql-meta-end
9898
*/
@@ -124,11 +124,11 @@ export const document = JSON.parse("{\\"kind\\":\\"Document\\",\\"definitions\\"
124124
"type": "output",
125125
},
126126
{
127-
"content": "// ts-gql-integrity:ac7e64affcc81f562d05e111d3c27a6b
127+
"content": "// ts-gql-integrity:6d6c397a1d8006b0a738ad42fc723ee6
128128
/*
129129
ts-gql-meta-begin
130130
{
131-
"hash": "04f29ddeac1a4c18c45826e8b2455c12"
131+
"hash": "b24eff4865db664cc1b11a1e8041e39b"
132132
}
133133
ts-gql-meta-end
134134
*/
@@ -171,11 +171,11 @@ exports[`optional and required variables 1`] = `
171171
"errors": [],
172172
"fsOperations": [
173173
{
174-
"content": "// ts-gql-integrity:ed1a914d3e6b6283f2f42ca20aeaa1c7
174+
"content": "// ts-gql-integrity:bb052f45eedd88e8dc2ccc4f231ed08b
175175
/*
176176
ts-gql-meta-begin
177177
{
178-
"hash": "356b740e682354cddaf8920961321b0b"
178+
"hash": "a27ca21ba64a9fe4c974b93318b54e5f"
179179
}
180180
ts-gql-meta-end
181181
*/
@@ -221,11 +221,11 @@ exports[`optional variable 1`] = `
221221
"errors": [],
222222
"fsOperations": [
223223
{
224-
"content": "// ts-gql-integrity:57764907a8978c4ab652dd1761473477
224+
"content": "// ts-gql-integrity:c1cc141959f3247c79537745cca1daee
225225
/*
226226
ts-gql-meta-begin
227227
{
228-
"hash": "8fc84f17e6e1117189b07f153fe0556e"
228+
"hash": "818b90303250f45865e4b45c31227566"
229229
}
230230
ts-gql-meta-end
231231
*/
@@ -270,11 +270,11 @@ exports[`required variable 1`] = `
270270
"errors": [],
271271
"fsOperations": [
272272
{
273-
"content": "// ts-gql-integrity:eb445e8f1e0fc2d163c3b6f1331a52da
273+
"content": "// ts-gql-integrity:7b6766cb31b723113da875033dcd5656
274274
/*
275275
ts-gql-meta-begin
276276
{
277-
"hash": "671294b97ed386cbd1f1f937d13c8454"
277+
"hash": "f4c9c7ad59a116d1fbce250d007e6f0f"
278278
}
279279
ts-gql-meta-end
280280
*/
@@ -319,11 +319,11 @@ exports[`something 1`] = `
319319
"errors": [],
320320
"fsOperations": [
321321
{
322-
"content": "// ts-gql-integrity:3a4e633001a2ebe718268e48e694fcf3
322+
"content": "// ts-gql-integrity:524c868e53a9925ae9e8519af94df806
323323
/*
324324
ts-gql-meta-begin
325325
{
326-
"hash": "b9a778f4067a83093c56c925a389cf01"
326+
"hash": "61fd5c447c9166b6e698683b2cd523a9"
327327
}
328328
ts-gql-meta-end
329329
*/
@@ -355,11 +355,11 @@ export const document = JSON.parse("{\\"kind\\":\\"Document\\",\\"definitions\\"
355355
"type": "output",
356356
},
357357
{
358-
"content": "// ts-gql-integrity:e1fa0d2bd4a5b6f928bb16711ce09d1f
358+
"content": "// ts-gql-integrity:49df1a1bd6a863494375f79ba5d34041
359359
/*
360360
ts-gql-meta-begin
361361
{
362-
"hash": "9f16e1355a3e37ea65d446e98f26162c"
362+
"hash": "76540d583ba229404eaa15ca5cdeb443"
363363
}
364364
ts-gql-meta-end
365365
*/
@@ -391,11 +391,11 @@ export const document = JSON.parse("{\\"kind\\":\\"Document\\",\\"definitions\\"
391391
"type": "output",
392392
},
393393
{
394-
"content": "// ts-gql-integrity:b66967fb35ee424fc53721db0fe28146
394+
"content": "// ts-gql-integrity:70e3346a90236cc2660ae4ff5e77dec2
395395
/*
396396
ts-gql-meta-begin
397397
{
398-
"hash": "40967a7756b270276b96576086c615f3"
398+
"hash": "27b9b4e968f73e9f7f8bb5b1b3e800b0"
399399
}
400400
ts-gql-meta-end
401401
*/
@@ -438,11 +438,11 @@ exports[`with directory that ends with .ts 1`] = `
438438
"errors": [],
439439
"fsOperations": [
440440
{
441-
"content": "// ts-gql-integrity:f6ea04fc77a35de27cc60303681c1fa7
441+
"content": "// ts-gql-integrity:997632f649b7de9f77dd86807bf02a84
442442
/*
443443
ts-gql-meta-begin
444444
{
445-
"hash": "4675d6839380c78593be64c208a1e269"
445+
"hash": "bf8896f7a97d11c70f4c40e769886c9a"
446446
}
447447
ts-gql-meta-end
448448
*/

0 commit comments

Comments
 (0)