Skip to content

Commit 6885c28

Browse files
committed
optional unions
1 parent 2d0b0e3 commit 6885c28

File tree

8 files changed

+21
-23
lines changed

8 files changed

+21
-23
lines changed

examples/typescript-node/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "typescript-node",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "",
55
"private": true,
66
"main": "index.js",
77
"type": "module",
88
"scripts": {
9+
"just-run": "node --loader ts-node/esm src/index.ts",
910
"start": "npm run generate-typescript-node && node --loader ts-node/esm src/index.ts",
10-
"generate-typescript-node": "node ../../packages/graphql-zeus/lib/index.js https://faker.graphqleditor.com/a-team/olympus/graphql ./src --n -g ./zeus.graphql --td",
11-
"generate-typescript-node-get": "node ../../packages/graphql-zeus/lib/index.js https://faker.graphqleditor.com/a-team/olympus/graphql ./src --n -g ./zeus.graphql --method=GET --td"
11+
"generate-typescript-node-config": "node ../../packages/graphql-zeus/lib/index.js --n -g ./zeus.graphql --td",
12+
"generate-typescript-node": "node ../../packages/graphql-zeus/lib/index.js https://faker.prod.graphqleditor.com/a-team/olympus/graphql ./src --n -g ./zeus.graphql --td",
13+
"generate-typescript-node-get": "node ../../packages/graphql-zeus/lib/index.js https://faker.prod.graphqleditor.com/a-team/olympus/graphql ./src --n -g ./zeus.graphql --method=GET --td"
1214
},
1315
"author": "Aexol <[email protected]> (http://aexol.com)",
1416
"license": "ISC",

examples/typescript-node/src/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const decoders = ZeusScalars({
6767
JSON: {
6868
encode: (e: unknown) => JSON.stringify(e),
6969
decode: (e: unknown) => {
70-
console.log(e);
70+
if (!e) return;
7171
return e as { power: number };
7272
},
7373
},
@@ -93,6 +93,7 @@ const run = async () => {
9393
},
9494
},
9595
{
96+
info: true,
9697
cardImage: {
9798
bucket: true,
9899
region: true,
@@ -112,9 +113,6 @@ const run = async () => {
112113
effectSize: true,
113114
name: true,
114115
},
115-
'...on SpecialCard': {
116-
name: true,
117-
},
118116
},
119117
});
120118
printQueryResult('drawChangeCard', blalba.drawChangeCard);
@@ -123,14 +121,15 @@ const run = async () => {
123121
info: true,
124122
},
125123
});
126-
if (typeof blalbaScalars.drawCard.info.power !== 'number') {
124+
console.log({ blalbaScalars });
125+
if (typeof blalbaScalars.drawCard.info?.power !== 'number') {
127126
throw new Error('Invalid scalar decoder');
128127
}
129128
printQueryResult('blalbaScalars', blalbaScalars.drawCard.info.power);
130129

131130
// Thunder example
132131
const thunder = Thunder(async (query) => {
133-
const response = await fetch('https://faker.graphqleditor.com/a-team/olympus/graphql', {
132+
const response = await fetch('https://faker.prod.graphqleditor.com/a-team/olympus/graphql', {
134133
body: JSON.stringify({ query }),
135134
method: 'POST',
136135
headers: {
@@ -167,9 +166,6 @@ const run = async () => {
167166
effectSize: true,
168167
name: true,
169168
},
170-
'...on SpecialCard': {
171-
name: true,
172-
},
173169
},
174170
});
175171
printQueryResult('drawChangeCard thunder', blalbaThunder.drawChangeCard);

examples/typescript-node/src/zeus/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { AllTypesProps, ReturnTypes, Ops } from './const.js';
44
import fetch, { Response } from 'node-fetch';
55
import WebSocket from 'ws';
6-
export const HOST = "https://faker.graphqleditor.com/a-team/olympus/graphql"
6+
export const HOST = "https://faker.prod.graphqleditor.com/a-team/olympus/graphql"
77

88

99
export const HEADERS = {}
@@ -960,8 +960,8 @@ powerups?: [{ filter: string | Variable<any, string>},ValueTypes["Powerup"]],
960960
name?:boolean | `@${string}`,
961961
__typename?: boolean | `@${string}`
962962
}>;
963-
["ChangeCard"]: AliasType<{ ["...on SpecialCard"] : ValueTypes["SpecialCard"],
964-
["...on EffectCard"] : ValueTypes["EffectCard"]
963+
["ChangeCard"]: AliasType<{ ["...on SpecialCard"]?: ValueTypes["SpecialCard"],
964+
["...on EffectCard"]?: ValueTypes["EffectCard"]
965965
__typename?: boolean | `@${string}`
966966
}>;
967967
["Subscription"]: AliasType<{

packages/graphql-zeus-core/TreeToTS/templates/valueTypes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const resolveValueTypeFromRoot = (i: ParserField, rootNodes: ParserField[], enum
1313
return `["${i.name}"]: ${AliasType(
1414
`{${i.args
1515
.map(
16-
(f) => `\t\t["...on ${getTypeName(f.type.fieldType)}"] : ${VALUETYPES}["${getTypeName(f.type.fieldType)}"]`,
16+
(f) => `\t\t["...on ${getTypeName(f.type.fieldType)}"]?: ${VALUETYPES}["${getTypeName(f.type.fieldType)}"]`,
1717
)
1818
.join(',\n')}\n\t\t__typename?: ${truthyType}\n}`,
1919
)}`;

packages/graphql-zeus-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus-core",
3-
"version": "5.4.4",
3+
"version": "5.4.5",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "GraphQL Editor, Artur Czemiel",

packages/graphql-zeus-jsonschema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus-jsonschema",
3-
"version": "5.4.4",
3+
"version": "5.4.5",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "GraphQL Editor, Artur Czemiel",

packages/graphql-zeus/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type ProjectOptions = {
1515
};
1616

1717
// eslint-disable-next-line @typescript-eslint/ban-types
18-
export const config = new ConfigMaker<ProjectOptions, {}>('graphql-zeus', {
18+
export const config = new ConfigMaker<ProjectOptions>('graphql-zeus', {
1919
decoders: {},
2020
defaultValues: {
2121
esModule: false,

packages/graphql-zeus/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus",
3-
"version": "5.4.4",
3+
"version": "5.4.5",
44
"private": false,
55
"scripts": {
66
"start": "ttsc --watch",
@@ -24,10 +24,10 @@
2424
"url": "https://github.com/graphql-editor/graphql-zeus.git"
2525
},
2626
"dependencies": {
27-
"config-maker": "^0.0.2",
27+
"config-maker": "^0.0.6",
2828
"cross-fetch": "^3.0.4",
29-
"graphql-zeus-core": "^5.4.4",
30-
"graphql-zeus-jsonschema": "^5.4.4",
29+
"graphql-zeus-core": "^5.4.5",
30+
"graphql-zeus-jsonschema": "^5.4.5",
3131
"yargs": "^16.1.1"
3232
}
3333
}

0 commit comments

Comments
 (0)