@avantstay/graphql-ts-client 10.7.0 → 10.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/chunk-I4QOADOI.mjs +27 -0
- package/dist/endpoint.d.ts +1 -1
- package/dist/endpoint.js +8 -3
- package/dist/endpoint.mjs +275 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.js +63 -51
- package/dist/index.mjs +527 -0
- package/dist/types-23d2d6aa.d.ts +75 -0
- package/dist/types-4ada662b.d.ts +70 -0
- package/package.json +43 -42
- package/src/__snapshots__/generateTypescriptClient.test.ts.snap +3 -2
- package/src/__testClient.d.ts +164 -0
- package/src/__testClient.js +135 -0
- package/src/endpoint.ts +8 -9
- package/src/generateTypescriptClient.test.ts +3 -3
- package/src/generateTypescriptClient.ts +32 -20
- package/src/graphqlRequest.test.ts +3 -4
- package/src/jsonToGraphQLQuery.ts +11 -8
- package/src/types.ts +32 -22
|
@@ -23,7 +23,7 @@ export function jsonToGraphQLQuery({
|
|
|
23
23
|
}) {
|
|
24
24
|
const variablesData = {} as ExtractedVariables
|
|
25
25
|
const alias = jsonQuery.__alias
|
|
26
|
-
const newJsonQuery = cloneDeep(omit(jsonQuery, ['__alias', '__headers']))
|
|
26
|
+
const newJsonQuery = cloneDeep(omit(jsonQuery, ['__alias', '__headers', '__url']))
|
|
27
27
|
|
|
28
28
|
extractVariables({
|
|
29
29
|
jsonQuery: { [queryName]: newJsonQuery },
|
|
@@ -31,14 +31,17 @@ export function jsonToGraphQLQuery({
|
|
|
31
31
|
parentType: kind === 'query' ? typesTree.Query : typesTree.Mutation,
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
const variableItems = Object.values(variablesData).reduce(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const variableItems = Object.values(variablesData).reduce(
|
|
35
|
+
(variablesObj, variables) => {
|
|
36
|
+
variables.forEach((variable, index) => {
|
|
37
|
+
const name = variable.update(variables.length > 1 ? index : undefined)
|
|
38
|
+
variablesObj[name] = { type: variable.type, value: variable.value }
|
|
39
|
+
})
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
return variablesObj
|
|
42
|
+
},
|
|
43
|
+
{} as Record<string, Variable>
|
|
44
|
+
)
|
|
42
45
|
|
|
43
46
|
const variablesQuery = Object.keys(variableItems).length
|
|
44
47
|
? `(${entries(variableItems)
|
package/src/types.ts
CHANGED
|
@@ -21,30 +21,34 @@ export type IResponseListener = (info: ResponseListenerInfo) => void | Promise<v
|
|
|
21
21
|
|
|
22
22
|
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
: Base
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
? Base
|
|
36
|
-
: Base
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
type Primitive = Date | string | number | boolean | null | undefined
|
|
25
|
+
|
|
26
|
+
// Projection is the resulting type of Selection (type generated out of a query) applied to Base (generated graphql type)
|
|
27
|
+
export type Projection<Selection, Base, E = never> =
|
|
28
|
+
Base extends Array<any>
|
|
29
|
+
? ArrayElement<Base> extends Primitive | E
|
|
30
|
+
? ArrayElement<Base>[]
|
|
31
|
+
: Projection<Defined<Selection>, ArrayElement<Base>, E>[]
|
|
32
|
+
: Base extends Primitive | E
|
|
33
|
+
? // Is primitive and extends undefined
|
|
34
|
+
Selection extends undefined
|
|
35
|
+
? Base | undefined
|
|
36
|
+
: Base
|
|
37
|
+
: {
|
|
38
|
+
[k in keyof Selection & keyof Base]: Selection[k] extends boolean
|
|
39
|
+
? Base[k]
|
|
40
|
+
: Base[k] extends Array<infer A>
|
|
41
|
+
? Projection<Defined<Selection[k]>, A, E>[]
|
|
42
|
+
: Projection<Defined<Selection[k]>, Base[k], E>
|
|
43
|
+
}
|
|
40
44
|
|
|
41
45
|
export type Unpacked<T> = T extends (infer U)[]
|
|
42
46
|
? U
|
|
43
47
|
: T extends (...args: any[]) => infer U
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
? U
|
|
49
|
+
: T extends Promise<infer U>
|
|
50
|
+
? U
|
|
51
|
+
: T
|
|
48
52
|
|
|
49
53
|
export type Replacement<M extends [any, any], T> = M extends any ? ([T] extends [M[0]] ? M[1] : never) : never
|
|
50
54
|
|
|
@@ -56,8 +60,8 @@ export type DeepReplace<T, Ignore, M extends [any, any]> = {
|
|
|
56
60
|
: T[P]
|
|
57
61
|
: Replacement<M, T[P]>
|
|
58
62
|
: T[P] extends object
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
? DeepReplace<T[P], Ignore, M>
|
|
64
|
+
: T[P]
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
export type RawEndpoint<I, O, E> = <S extends I>(
|
|
@@ -95,6 +99,12 @@ export type LogInfo = {
|
|
|
95
99
|
duration: number
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
export type TypescriptClientOutput = {
|
|
103
|
+
js: string
|
|
104
|
+
mjs: string
|
|
105
|
+
typings: string
|
|
106
|
+
}
|
|
107
|
+
|
|
98
108
|
export class GraphQLClientError extends Error {
|
|
99
109
|
responseData: ResponseData
|
|
100
110
|
|