Skip to content

Commit

Permalink
optional unions
Browse files Browse the repository at this point in the history
  • Loading branch information
aexol committed Aug 23, 2024
1 parent 2d0b0e3 commit 6885c28
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 23 deletions.
8 changes: 5 additions & 3 deletions examples/typescript-node/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "typescript-node",
"version": "1.2.4",
"version": "1.2.5",
"description": "",
"private": true,
"main": "index.js",
"type": "module",
"scripts": {
"just-run": "node --loader ts-node/esm src/index.ts",
"start": "npm run generate-typescript-node && node --loader ts-node/esm src/index.ts",
"generate-typescript-node": "node ../../packages/graphql-zeus/lib/index.js https://faker.graphqleditor.com/a-team/olympus/graphql ./src --n -g ./zeus.graphql --td",
"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"
"generate-typescript-node-config": "node ../../packages/graphql-zeus/lib/index.js --n -g ./zeus.graphql --td",
"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",
"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"
},
"author": "Aexol <[email protected]> (http://aexol.com)",
"license": "ISC",
Expand Down
14 changes: 5 additions & 9 deletions examples/typescript-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const decoders = ZeusScalars({
JSON: {
encode: (e: unknown) => JSON.stringify(e),
decode: (e: unknown) => {
console.log(e);
if (!e) return;
return e as { power: number };
},
},
Expand All @@ -93,6 +93,7 @@ const run = async () => {
},
},
{
info: true,
cardImage: {
bucket: true,
region: true,
Expand All @@ -112,9 +113,6 @@ const run = async () => {
effectSize: true,
name: true,
},
'...on SpecialCard': {
name: true,
},
},
});
printQueryResult('drawChangeCard', blalba.drawChangeCard);
Expand All @@ -123,14 +121,15 @@ const run = async () => {
info: true,
},
});
if (typeof blalbaScalars.drawCard.info.power !== 'number') {
console.log({ blalbaScalars });
if (typeof blalbaScalars.drawCard.info?.power !== 'number') {
throw new Error('Invalid scalar decoder');
}
printQueryResult('blalbaScalars', blalbaScalars.drawCard.info.power);

// Thunder example
const thunder = Thunder(async (query) => {
const response = await fetch('https://faker.graphqleditor.com/a-team/olympus/graphql', {
const response = await fetch('https://faker.prod.graphqleditor.com/a-team/olympus/graphql', {
body: JSON.stringify({ query }),
method: 'POST',
headers: {
Expand Down Expand Up @@ -167,9 +166,6 @@ const run = async () => {
effectSize: true,
name: true,
},
'...on SpecialCard': {
name: true,
},
},
});
printQueryResult('drawChangeCard thunder', blalbaThunder.drawChangeCard);
Expand Down
6 changes: 3 additions & 3 deletions examples/typescript-node/src/zeus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { AllTypesProps, ReturnTypes, Ops } from './const.js';
import fetch, { Response } from 'node-fetch';
import WebSocket from 'ws';
export const HOST = "https://faker.graphqleditor.com/a-team/olympus/graphql"
export const HOST = "https://faker.prod.graphqleditor.com/a-team/olympus/graphql"


export const HEADERS = {}
Expand Down Expand Up @@ -960,8 +960,8 @@ powerups?: [{ filter: string | Variable<any, string>},ValueTypes["Powerup"]],
name?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["ChangeCard"]: AliasType<{ ["...on SpecialCard"] : ValueTypes["SpecialCard"],
["...on EffectCard"] : ValueTypes["EffectCard"]
["ChangeCard"]: AliasType<{ ["...on SpecialCard"]?: ValueTypes["SpecialCard"],
["...on EffectCard"]?: ValueTypes["EffectCard"]
__typename?: boolean | `@${string}`
}>;
["Subscription"]: AliasType<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const resolveValueTypeFromRoot = (i: ParserField, rootNodes: ParserField[], enum
return `["${i.name}"]: ${AliasType(
`{${i.args
.map(
(f) => `\t\t["...on ${getTypeName(f.type.fieldType)}"] : ${VALUETYPES}["${getTypeName(f.type.fieldType)}"]`,
(f) => `\t\t["...on ${getTypeName(f.type.fieldType)}"]?: ${VALUETYPES}["${getTypeName(f.type.fieldType)}"]`,
)
.join(',\n')}\n\t\t__typename?: ${truthyType}\n}`,
)}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-zeus-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-zeus-core",
"version": "5.4.4",
"version": "5.4.5",
"private": false,
"main": "./lib/index.js",
"author": "GraphQL Editor, Artur Czemiel",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-zeus-jsonschema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-zeus-jsonschema",
"version": "5.4.4",
"version": "5.4.5",
"private": false,
"main": "./lib/index.js",
"author": "GraphQL Editor, Artur Czemiel",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-zeus/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ProjectOptions = {
};

// eslint-disable-next-line @typescript-eslint/ban-types
export const config = new ConfigMaker<ProjectOptions, {}>('graphql-zeus', {
export const config = new ConfigMaker<ProjectOptions>('graphql-zeus', {
decoders: {},
defaultValues: {
esModule: false,
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql-zeus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-zeus",
"version": "5.4.4",
"version": "5.4.5",
"private": false,
"scripts": {
"start": "ttsc --watch",
Expand All @@ -24,10 +24,10 @@
"url": "https://github.com/graphql-editor/graphql-zeus.git"
},
"dependencies": {
"config-maker": "^0.0.2",
"config-maker": "^0.0.6",
"cross-fetch": "^3.0.4",
"graphql-zeus-core": "^5.4.4",
"graphql-zeus-jsonschema": "^5.4.4",
"graphql-zeus-core": "^5.4.5",
"graphql-zeus-jsonschema": "^5.4.5",
"yargs": "^16.1.1"
}
}

0 comments on commit 6885c28

Please sign in to comment.