Skip to content

Commit d302f9d

Browse files
committed
repaired fields function now should work with everything
1 parent 55ce951 commit d302f9d

File tree

13 files changed

+59
-69
lines changed

13 files changed

+59
-69
lines changed

examples/typescript-node/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
{
22
"name": "typescript-node",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"description": "",
55
"private": true,
66
"main": "index.js",
77
"type": "module",
88
"scripts": {
99
"just-run": "node --loader ts-node/esm src/index.ts",
10-
"start": "npm run generate-typescript-node && node --loader ts-node/esm src/index.ts",
10+
"start": "npm run generate-typescript-node && node --import=tsx src/index.ts",
1111
"generate-typescript-node-config": "node ../../packages/graphql-zeus/lib/index.js --n -g ./zeus.graphql --td",
1212
"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",
1313
"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"
1414
},
1515
"author": "Aexol <[email protected]> (http://aexol.com)",
1616
"license": "ISC",
1717
"devDependencies": {
18-
"@graphql-typed-document-node/core": "^3.1.1"
18+
"@graphql-typed-document-node/core": "^3.1.1",
19+
"tsx": "^4.19.2"
1920
},
2021
"dependencies": {
2122
"@apollo/client": "^3.4.16",

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export const AllTypesProps: Record<string,any> = {
1313
Card:{
1414
attack:{
1515

16+
},
17+
testFn:{
18+
1619
}
1720
},
1821
Mutation:{
@@ -60,7 +63,8 @@ export const ReturnTypes: Record<string,any> = {
6063
image:"String",
6164
info:"JSON",
6265
name:"String",
63-
skills:"SpecialSkills"
66+
skills:"SpecialSkills",
67+
testFn:"String"
6468
},
6569
SpecialCard:{
6670
effect:"String",

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,30 @@ export const Gql = Chain(HOST, {
279279

280280
export const ZeusScalars = ZeusSelect<ScalarCoders>();
281281

282+
type BaseSymbol = number | string | undefined | boolean | null;
283+
282284
type ScalarsSelector<T> = {
283285
[X in Required<{
284-
[P in keyof T]: T[P] extends number | string | undefined | boolean ? P : never;
286+
[P in keyof T]: T[P] extends BaseSymbol | Array<BaseSymbol> ? P : never;
285287
}>[keyof T]]: true;
286288
};
287289

288290
export const fields = <T extends keyof ModelTypes>(k: T) => {
289291
const t = ReturnTypes[k];
292+
const fnType = k in AllTypesProps ? AllTypesProps[k as keyof typeof AllTypesProps] : undefined;
293+
const hasFnTypes = typeof fnType === 'object' ? fnType : undefined;
290294
const o = Object.fromEntries(
291295
Object.entries(t)
292-
.filter(([, value]) => {
296+
.filter(([k, value]) => {
297+
const isFunctionType = hasFnTypes && k in hasFnTypes && !!hasFnTypes[k as keyof typeof hasFnTypes];
298+
if (isFunctionType) return false;
293299
const isReturnType = ReturnTypes[value as string];
294-
if (!isReturnType || (typeof isReturnType === 'string' && isReturnType.startsWith('scalar.'))) {
300+
if (!isReturnType) return true;
301+
if (typeof isReturnType !== 'string') return false;
302+
if (isReturnType.startsWith('scalar.')) {
295303
return true;
296304
}
305+
return false;
297306
})
298307
.map(([key]) => [key, true as const]),
299308
);
@@ -949,6 +958,7 @@ attack?: [{ /** Attacked card/card ids<br> */
949958
/** The name of a card<br> */
950959
name?:boolean | `@${string}`,
951960
skills?:boolean | `@${string}`,
961+
testFn?: [{ test?: string | undefined | null | Variable<any, string>},boolean | `@${string}`],
952962
__typename?: boolean | `@${string}`
953963
}>;
954964
["SpecialCard"]: AliasType<{
@@ -1054,6 +1064,7 @@ attack?: [{ /** Attacked card/card ids<br> */
10541064
/** The name of a card<br> */
10551065
name?:boolean | `@${string}`,
10561066
skills?:boolean | `@${string}`,
1067+
testFn?: [{ test?: string | undefined | null},boolean | `@${string}`],
10571068
__typename?: boolean | `@${string}`
10581069
}>;
10591070
["SpecialCard"]: AliasType<{
@@ -1156,7 +1167,8 @@ export type ModelTypes = {
11561167
info: ModelTypes["JSON"],
11571168
/** The name of a card<br> */
11581169
name: string,
1159-
skills?: Array<ModelTypes["SpecialSkills"]> | undefined | null
1170+
skills?: Array<ModelTypes["SpecialSkills"]> | undefined | null,
1171+
testFn?: string | undefined | null
11601172
};
11611173
["SpecialCard"]: {
11621174
effect: string,
@@ -1257,7 +1269,8 @@ export type GraphQLTypes = {
12571269
info: GraphQLTypes["JSON"],
12581270
/** The name of a card<br> */
12591271
name: string,
1260-
skills?: Array<GraphQLTypes["SpecialSkills"]> | undefined | null
1272+
skills?: Array<GraphQLTypes["SpecialSkills"]> | undefined | null,
1273+
testFn?: string | undefined | null
12611274
};
12621275
["SpecialCard"]: {
12631276
__typename: "SpecialCard",

examples/typescript-node/zeus.graphql

+1-46
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
""""""
21
interface Nameable {
3-
""""""
42
name: String!
53
}
64

7-
""""""
85
enum SpecialSkills {
96
"""Lower enemy defense -5<br>"""
107
THUNDER
@@ -16,27 +13,17 @@ enum SpecialSkills {
1613
FIRE
1714
}
1815

19-
""""""
2016
type Query {
21-
""""""
2217
cardById(cardId: String): Card
2318

2419
"""Draw a card<br>"""
2520
drawCard: Card!
26-
27-
""""""
2821
drawChangeCard: ChangeCard!
2922

3023
"""list All Cards availble<br>"""
3124
listCards: [Card!]!
32-
33-
""""""
3425
myStacks: [CardStack!]
35-
36-
""""""
3726
nameables: [Nameable!]!
38-
39-
""""""
4027
public: Public
4128
}
4229

@@ -63,10 +50,7 @@ input createCard {
6350

6451
"""Stack of cards"""
6552
type CardStack implements Nameable {
66-
""""""
6753
cards: [Card!]
68-
69-
""""""
7054
name: String!
7155
}
7256

@@ -92,80 +76,51 @@ type Card implements Nameable {
9276

9377
"""Description of a card<br>"""
9478
description: String!
95-
96-
""""""
9779
id: ID!
98-
99-
""""""
10080
image: String!
101-
102-
""""""
10381
info: JSON!
10482

10583
"""The name of a card<br>"""
10684
name: String!
107-
108-
""""""
10985
skills: [SpecialSkills!]
86+
testFn(test: String): String
11087
}
11188

112-
""""""
11389
type SpecialCard implements Nameable {
114-
""""""
11590
effect: String!
116-
117-
""""""
11891
name: String!
11992
}
12093

121-
""""""
12294
type EffectCard implements Nameable {
123-
""""""
12495
effectSize: Float!
125-
126-
""""""
12796
name: String!
12897
}
12998

130-
""""""
13199
type Mutation {
132100
"""add Card to Cards database<br>"""
133101
addCard(card: createCard!): Card!
134102
}
135103

136-
""""""
137104
scalar JSON
138105

139106
"""Aws S3 File"""
140107
type S3Object {
141-
""""""
142108
bucket: String!
143-
144-
""""""
145109
key: String!
146-
147-
""""""
148110
region: String!
149111
}
150112

151-
""""""
152113
type Public {
153-
""""""
154114
powerups(filter: String!): [Powerup!]
155115
}
156116

157-
""""""
158117
type Powerup {
159-
""""""
160118
name: String
161119
}
162120

163-
""""""
164121
union ChangeCard = SpecialCard | EffectCard
165122

166-
""""""
167123
type Subscription {
168-
""""""
169124
deck: [Card!]
170125
}
171126
schema{

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@commitlint/config-conventional": "^8.3.4",
2727
"@types/graphql": "^14.5.0",
2828
"@types/jest": "^29.1.2",
29-
"@types/node": "^18.11.2",
29+
"@types/node": "^22.10.3",
3030
"@types/node-fetch": "^2.3.7",
3131
"@types/ws": "^8.5.3",
3232
"@types/yargs": "^15.0.11",

packages/graphql-zeus-core/TreeToTS/functions/generated.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,30 @@ export const Gql = Chain(HOST, {
238238
239239
export const ZeusScalars = ZeusSelect<ScalarCoders>();
240240
241+
type BaseSymbol = number | string | undefined | boolean | null;
242+
241243
type ScalarsSelector<T> = {
242244
[X in Required<{
243-
[P in keyof T]: T[P] extends number | string | undefined | boolean ? P : never;
245+
[P in keyof T]: T[P] extends BaseSymbol | Array<BaseSymbol> ? P : never;
244246
}>[keyof T]]: true;
245247
};
246248
247249
export const fields = <T extends keyof ModelTypes>(k: T) => {
248250
const t = ReturnTypes[k];
251+
const fnType = k in AllTypesProps ? AllTypesProps[k as keyof typeof AllTypesProps] : undefined;
252+
const hasFnTypes = typeof fnType === 'object' ? fnType : undefined;
249253
const o = Object.fromEntries(
250254
Object.entries(t)
251-
.filter(([, value]) => {
255+
.filter(([k, value]) => {
256+
const isFunctionType = hasFnTypes && k in hasFnTypes && !!hasFnTypes[k as keyof typeof hasFnTypes];
257+
if (isFunctionType) return false;
252258
const isReturnType = ReturnTypes[value as string];
253-
if (!isReturnType || (typeof isReturnType === 'string' && isReturnType.startsWith('scalar.'))) {
259+
if (!isReturnType) return true;
260+
if (typeof isReturnType !== 'string') return false;
261+
if (isReturnType.startsWith('scalar.')) {
254262
return true;
255263
}
264+
return false;
256265
})
257266
.map(([key]) => [key, true as const]),
258267
);

packages/graphql-zeus-core/TreeToTS/functions/new/clientFunctions.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,30 @@ export const Gql = Chain(HOST, {
146146

147147
export const ZeusScalars = ZeusSelect<ScalarCoders>();
148148

149+
type BaseSymbol = number | string | undefined | boolean | null;
150+
149151
type ScalarsSelector<T> = {
150152
[X in Required<{
151-
[P in keyof T]: T[P] extends number | string | undefined | boolean ? P : never;
153+
[P in keyof T]: T[P] extends BaseSymbol | Array<BaseSymbol> ? P : never;
152154
}>[keyof T]]: true;
153155
};
154156

155157
export const fields = <T extends keyof ModelTypes>(k: T) => {
156158
const t = ReturnTypes[k];
159+
const fnType = k in AllTypesProps ? AllTypesProps[k as keyof typeof AllTypesProps] : undefined;
160+
const hasFnTypes = typeof fnType === 'object' ? fnType : undefined;
157161
const o = Object.fromEntries(
158162
Object.entries(t)
159-
.filter(([, value]) => {
163+
.filter(([k, value]) => {
164+
const isFunctionType = hasFnTypes && k in hasFnTypes && !!hasFnTypes[k as keyof typeof hasFnTypes];
165+
if (isFunctionType) return false;
160166
const isReturnType = ReturnTypes[value as string];
161-
if (!isReturnType || (typeof isReturnType === 'string' && isReturnType.startsWith('scalar.'))) {
167+
if (!isReturnType) return true;
168+
if (typeof isReturnType !== 'string') return false;
169+
if (isReturnType.startsWith('scalar.')) {
162170
return true;
163171
}
172+
return false;
164173
})
165174
.map(([key]) => [key, true as const]),
166175
);

packages/graphql-zeus-core/jest.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ module.exports = {
66
},
77
testMatch: ['<rootDir>/**/*.spec.(ts|tsx)'],
88
watchPathIgnorePatterns: ['node_modules'],
9-
watchman: false,
109
};

packages/graphql-zeus-core/package.json

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

packages/graphql-zeus-jsonschema/jest.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ module.exports = {
66
},
77
testMatch: ['<rootDir>/**/*.spec.(ts|tsx)'],
88
watchPathIgnorePatterns: ['node_modules'],
9-
watchman: false,
109
};

packages/graphql-zeus-jsonschema/package.json

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

packages/graphql-zeus/CLIClass.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class CLI {
4545
const commandLineProvidedOptions = { ...args, urlOrPath: allArgs[0] };
4646
const schemaFile = await config.getValueOrThrow('urlOrPath', {
4747
commandLineProvidedOptions,
48+
saveOnInput: true,
4849
});
4950
let host: string | undefined;
5051
if (schemaFile.startsWith('http://') || schemaFile.startsWith('https://')) {

packages/graphql-zeus/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus",
3-
"version": "7.0.2",
3+
"version": "7.0.3",
44
"private": false,
55
"scripts": {
66
"start": "ttsc --watch",
@@ -26,8 +26,8 @@
2626
"dependencies": {
2727
"config-maker": "^0.0.6",
2828
"cross-fetch": "^3.0.4",
29-
"graphql-zeus-core": "^7.0.2",
30-
"graphql-zeus-jsonschema": "^7.0.2",
29+
"graphql-zeus-core": "^7.0.3",
30+
"graphql-zeus-jsonschema": "^7.0.3",
3131
"yargs": "^16.1.1"
3232
}
3333
}

0 commit comments

Comments
 (0)