@avantstay/graphql-ts-client 10.8.0 → 11.0.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.
@@ -1,13 +1,13 @@
1
- import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-85e628f6.js';
1
+ import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-4ada662b.js';
2
2
 
3
- declare const getApiEndpointCreator: (apiConfig: {
4
- getClient: () => ClientConfig;
5
- responseListeners: IResponseListener[];
6
- typesTree: any;
7
- maxAge: number;
8
- verbose: boolean;
9
- formatGraphQL: any;
10
- errorsParser?: ((errors: any[]) => any) | undefined;
3
+ declare const getApiEndpointCreator: (apiConfig: {
4
+ getClient: () => ClientConfig;
5
+ responseListeners: IResponseListener[];
6
+ typesTree: any;
7
+ maxAge: number;
8
+ verbose: boolean;
9
+ formatGraphQL: any;
10
+ errorsParser?: ((errors: any[]) => any) | undefined;
11
11
  }) => <I = any, O = any, E = any>(kind: 'mutation' | 'query', queryName: string) => Endpoint<I, O, E>;
12
12
 
13
13
  export { getApiEndpointCreator };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,24 @@
1
1
  import { PathLike } from 'fs';
2
- export { C as ClientConfig, c as DeepReplace, D as Defined, E as Endpoint, G as GraphQLClientError, I as IResponseListener, J as JsonOutput, L as LogInfo, M as Maybe, P as Projection, d as RawEndpoint, b as Replacement, R as ResponseData, a as ResponseListenerInfo, U as Unpacked } from './types-85e628f6.js';
2
+ export { C as ClientConfig, c as DeepReplace, D as Defined, E as Endpoint, G as GraphQLClientError, I as IResponseListener, J as JsonOutput, L as LogInfo, M as Maybe, P as Projection, d as RawEndpoint, b as Replacement, R as ResponseData, a as ResponseListenerInfo, U as Unpacked } from './types-4ada662b.js';
3
3
 
4
- type IClientOptions = {
5
- output?: PathLike;
6
- clientName?: string;
7
- headers?: {
8
- [key: string]: string;
9
- };
10
- introspectionEndpoint?: string;
11
- endpoint: string;
12
- verbose?: boolean;
13
- formatGraphQL?: boolean;
14
- skipCache?: boolean;
15
- errorsParser?: (errors: any[]) => any;
16
- };
17
- type Client = {
18
- typings: string;
19
- js: string;
20
- };
21
- declare function generateTypescriptClient({ introspectionEndpoint, ...options }: IClientOptions): Promise<Client>;
4
+ type IClientOptions = {
5
+ output?: PathLike;
6
+ clientName?: string;
7
+ headers?: {
8
+ [key: string]: string;
9
+ };
10
+ introspectionEndpoint?: string;
11
+ endpoint: string;
12
+ verbose?: boolean;
13
+ formatGraphQL?: boolean;
14
+ skipCache?: boolean;
15
+ errorsParser?: (errors: any[]) => any;
16
+ };
17
+ type Client = {
18
+ typings: string;
19
+ js: string;
20
+ };
21
+ declare function generateTypescriptClient({ introspectionEndpoint, ...options }: IClientOptions): Promise<Client>;
22
22
  declare function generateTypescriptClientFromSDL(SDL: string, options: IClientOptions): Client;
23
23
 
24
24
  export { generateTypescriptClient, generateTypescriptClientFromSDL };
package/dist/index.js CHANGED
@@ -487,7 +487,7 @@ var prettier = __toESM(require("prettier"));
487
487
  // package.json
488
488
  var package_default = {
489
489
  name: "@avantstay/graphql-ts-client",
490
- version: "10.8.0",
490
+ version: "11.0.0",
491
491
  description: "GraphQL Typescript Client Generator",
492
492
  author: "Wellington Guimaraes",
493
493
  license: "MIT",
@@ -683,8 +683,7 @@ function gqlEndpointToCode(kind, endpoint, codeOutputType) {
683
683
  var outputType = gqlTypeToTypescript(endpoint.type, {
684
684
  required: true
685
685
  });
686
- var wrappedOutputType = /^(string|number|boolean)$/.test(outputType) ? outputType : "DeepRequired<".concat(outputType, ">");
687
- return codeOutputType === "ts" ? "".concat(endpoint.name, ": Endpoint<").concat(inputType, ", ").concat(wrappedOutputType, ", AllEnums>") : "".concat(endpoint.name, ": apiEndpoint('").concat(kind, "', '").concat(endpoint.name, "')");
686
+ return codeOutputType === "ts" ? "".concat(endpoint.name, ": Endpoint<").concat(inputType, ", ").concat(outputType, ", AllEnums>") : "".concat(endpoint.name, ": apiEndpoint('").concat(kind, "', '").concat(endpoint.name, "')");
688
687
  }
689
688
  function gqlSchemaToCode(gqlType, param) {
690
689
  var _param_selection = param.selection, selection = _param_selection === void 0 ? false : _param_selection, outputType = param.outputType;
@@ -1,69 +1,70 @@
1
- type Maybe<T> = null | undefined | T;
2
- type Defined<T> = Exclude<T, undefined>;
3
- type ResponseData = {
4
- data: any;
5
- warnings: any;
6
- headers: any;
7
- status?: number;
8
- errors: {
9
- message: string;
10
- }[];
11
- };
12
- type ResponseListenerInfo = {
13
- queryName: string;
14
- query: string;
15
- variables: any;
16
- response: ResponseData;
17
- };
18
- type IResponseListener = (info: ResponseListenerInfo) => void | Promise<void>;
19
- type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
20
- type Projection<Selection, Base, E = never> = Base extends Array<any> ? ArrayElement<Base> extends Date | string | number | boolean | null | undefined | E ? ArrayElement<Base>[] : Projection<Defined<Selection>, ArrayElement<Base>, E>[] : Base extends Date | string | number | boolean | null | E ? Selection extends undefined ? Base | undefined : Base : {
21
- [k in keyof Selection & keyof Base]: Selection[k] extends boolean ? Base[k] : Base[k] extends Array<infer A> ? Projection<Defined<Selection[k]>, A, E>[] : Projection<Defined<Selection[k]>, Base[k], E>;
22
- };
23
- type Unpacked<T> = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise<infer U> ? U : T;
24
- type Replacement<M extends [any, any], T> = M extends any ? ([T] extends [M[0]] ? M[1] : never) : never;
25
- type DeepReplace<T, Ignore, M extends [any, any]> = {
26
- [P in keyof T]: T[P] extends M[0] ? T[P] extends Ignore ? T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P] : Replacement<M, T[P]> : T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P];
27
- };
28
- type RawEndpoint<I, O, E> = <S extends I>(jsonQuery?: S) => Promise<{
29
- data: Projection<S, O, E>;
30
- errors: any[];
31
- warnings: any[];
32
- headers: any;
33
- status: any;
34
- }>;
35
- type JsonOutput<O, ToBeIgnored> = DeepReplace<O, ToBeIgnored, [string | Date, string]>;
36
- type Endpoint<I, O, E> = (<S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>) & {
37
- memo: <S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>;
38
- memoRaw: RawEndpoint<I, JsonOutput<O, E>, E>;
39
- raw: RawEndpoint<I, JsonOutput<O, E>, E>;
40
- };
41
- type ClientConfig = {
42
- url: string;
43
- headers: {
44
- [key: string]: string;
45
- };
46
- retryConfig: {
47
- max: number;
48
- waitBeforeRetry?: number;
49
- before: IResponseListener;
50
- };
51
- };
52
- type LogInfo = {
53
- query: string;
54
- variables: any;
55
- formatGraphQL: any;
56
- kind: string;
57
- queryName: string;
58
- response?: any;
59
- error?: Error;
60
- duration: number;
61
- };
62
- declare class GraphQLClientError extends Error {
63
- responseData: ResponseData;
64
- constructor(responseData: ResponseData);
65
- get message(): string;
66
- get response(): ResponseData;
1
+ type Maybe<T> = null | undefined | T;
2
+ type Defined<T> = Exclude<T, undefined>;
3
+ type ResponseData = {
4
+ data: any;
5
+ warnings: any;
6
+ headers: any;
7
+ status?: number;
8
+ errors: {
9
+ message: string;
10
+ }[];
11
+ };
12
+ type ResponseListenerInfo = {
13
+ queryName: string;
14
+ query: string;
15
+ variables: any;
16
+ response: ResponseData;
17
+ };
18
+ type IResponseListener = (info: ResponseListenerInfo) => void | Promise<void>;
19
+ type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
20
+ type Primitive = Date | string | number | boolean | null | undefined;
21
+ type Projection<Selection, Base, E = never> = Base extends Array<any> ? ArrayElement<Base> extends Primitive | E ? ArrayElement<Base>[] : Projection<Defined<Selection>, ArrayElement<Base>, E>[] : Base extends Primitive | E ? Selection extends undefined ? Base | undefined : Base : {
22
+ [k in keyof Selection & keyof Base]: Selection[k] extends boolean ? Base[k] : Base[k] extends Array<infer A> ? Projection<Defined<Selection[k]>, A, E>[] : Projection<Defined<Selection[k]>, Base[k], E>;
23
+ };
24
+ type Unpacked<T> = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise<infer U> ? U : T;
25
+ type Replacement<M extends [any, any], T> = M extends any ? ([T] extends [M[0]] ? M[1] : never) : never;
26
+ type DeepReplace<T, Ignore, M extends [any, any]> = {
27
+ [P in keyof T]: T[P] extends M[0] ? T[P] extends Ignore ? T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P] : Replacement<M, T[P]> : T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P];
28
+ };
29
+ type RawEndpoint<I, O, E> = <S extends I>(jsonQuery?: S) => Promise<{
30
+ data: Projection<S, O, E>;
31
+ errors: any[];
32
+ warnings: any[];
33
+ headers: any;
34
+ status: any;
35
+ }>;
36
+ type JsonOutput<O, ToBeIgnored> = DeepReplace<O, ToBeIgnored, [string | Date, string]>;
37
+ type Endpoint<I, O, E> = (<S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>) & {
38
+ memo: <S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>;
39
+ memoRaw: RawEndpoint<I, JsonOutput<O, E>, E>;
40
+ raw: RawEndpoint<I, JsonOutput<O, E>, E>;
41
+ };
42
+ type ClientConfig = {
43
+ url: string;
44
+ headers: {
45
+ [key: string]: string;
46
+ };
47
+ retryConfig: {
48
+ max: number;
49
+ waitBeforeRetry?: number;
50
+ before: IResponseListener;
51
+ };
52
+ };
53
+ type LogInfo = {
54
+ query: string;
55
+ variables: any;
56
+ formatGraphQL: any;
57
+ kind: string;
58
+ queryName: string;
59
+ response?: any;
60
+ error?: Error;
61
+ duration: number;
62
+ };
63
+ declare class GraphQLClientError extends Error {
64
+ responseData: ResponseData;
65
+ constructor(responseData: ResponseData);
66
+ get message(): string;
67
+ get response(): ResponseData;
67
68
  }
68
69
 
69
70
  export { ClientConfig as C, Defined as D, Endpoint as E, GraphQLClientError as G, IResponseListener as I, JsonOutput as J, LogInfo as L, Maybe as M, Projection as P, ResponseData as R, Unpacked as U, ResponseListenerInfo as a, Replacement as b, DeepReplace as c, RawEndpoint as d };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avantstay/graphql-ts-client",
3
- "version": "10.8.0",
3
+ "version": "11.0.0",
4
4
  "description": "GraphQL Typescript Client Generator",
5
5
  "author": "Wellington Guimaraes",
6
6
  "license": "MIT",
@@ -39,6 +39,16 @@ export interface Book {
39
39
  author?: string
40
40
  type?: BookType
41
41
  dateCreated?: ISODate
42
+ sequence?: BookSequence
43
+ }
44
+
45
+ /**
46
+ * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
47
+ */
48
+
49
+ export interface BookSequence {
50
+ previousBook?: Book
51
+ nextBook?: Book
42
52
  }
43
53
 
44
54
  /**
@@ -78,6 +88,12 @@ export interface BookSelection {
78
88
  author?: boolean
79
89
  type?: boolean
80
90
  dateCreated?: boolean
91
+ sequence?: BookSequenceSelection
92
+ }
93
+
94
+ export interface BookSequenceSelection {
95
+ previousBook?: BookSelection
96
+ nextBook?: BookSelection
81
97
  }
82
98
 
83
99
  export interface BookSearchParamsAllOptionalSelection {
@@ -107,7 +123,6 @@ export declare const myApiClient: {
107
123
  __headers?: { [key: string]: string }
108
124
  __retry?: boolean
109
125
  __alias?: string
110
- __url?: string
111
126
  } & BookSelection,
112
127
  DeepRequired<Book[]>,
113
128
  AllEnums
@@ -117,7 +132,6 @@ export declare const myApiClient: {
117
132
  __headers?: { [key: string]: string }
118
133
  __retry?: boolean
119
134
  __alias?: string
120
- __url?: string
121
135
  __args?: BooksWithOptionalParamsArgs
122
136
  } & BookSelection,
123
137
  DeepRequired<Book[]>,
@@ -128,7 +142,6 @@ export declare const myApiClient: {
128
142
  __headers?: { [key: string]: string }
129
143
  __retry?: boolean
130
144
  __alias?: string
131
- __url?: string
132
145
  __args: BooksWithRequiredParamsArgs
133
146
  } & BookSelection,
134
147
  DeepRequired<Book[]>,
@@ -139,7 +152,6 @@ export declare const myApiClient: {
139
152
  __headers?: { [key: string]: string }
140
153
  __retry?: boolean
141
154
  __alias?: string
142
- __url?: string
143
155
  __args: FailingQueryArgs
144
156
  },
145
157
  string,
@@ -39,6 +39,7 @@ const typesTree = {
39
39
  Query: {
40
40
  get booksWithOptionalParams() {
41
41
  return {
42
+ __fields: typesTree.Book,
42
43
  __args: {
43
44
  params: "BookSearchParamsAllOptional!"
44
45
  }
@@ -46,6 +47,7 @@ const typesTree = {
46
47
  },
47
48
  get booksWithRequiredParams() {
48
49
  return {
50
+ __fields: typesTree.Book,
49
51
  __args: {
50
52
  params: "BookSearchParamsSomeRequired!"
51
53
  }
@@ -58,7 +60,30 @@ const typesTree = {
58
60
  }
59
61
  };
60
62
  },
61
- booksWithoutParams: {}
63
+ get booksWithoutParams() {
64
+ return {
65
+ __fields: typesTree.Book
66
+ };
67
+ }
68
+ },
69
+ Book: {
70
+ get sequence() {
71
+ return {
72
+ __fields: typesTree.BookSequence
73
+ };
74
+ }
75
+ },
76
+ BookSequence: {
77
+ get previousBook() {
78
+ return {
79
+ __fields: typesTree.Book
80
+ };
81
+ },
82
+ get nextBook() {
83
+ return {
84
+ __fields: typesTree.Book
85
+ };
86
+ }
62
87
  }
63
88
  };
64
89
  let verbose = false;
@@ -153,10 +153,9 @@ function gqlEndpointToCode(kind: 'mutation' | 'query', endpoint: IntrospectionFi
153
153
  }${selectionType ? ` & ${selectionType}` : ''}`
154
154
 
155
155
  const outputType = gqlTypeToTypescript(endpoint.type, { required: true })
156
- const wrappedOutputType = /^(string|number|boolean)$/.test(outputType) ? outputType : `DeepRequired<${outputType}>`
157
156
 
158
157
  return codeOutputType === 'ts'
159
- ? `${endpoint.name}: Endpoint<${inputType}, ${wrappedOutputType}, AllEnums>`
158
+ ? `${endpoint.name}: Endpoint<${inputType}, ${outputType}, AllEnums>`
160
159
  : `${endpoint.name}: apiEndpoint('${kind}', '${endpoint.name}')`
161
160
  }
162
161
 
package/src/types.ts CHANGED
@@ -21,11 +21,14 @@ 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
+ 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)
24
27
  export type Projection<Selection, Base, E = never> = Base extends Array<any>
25
- ? ArrayElement<Base> extends Date | string | number | boolean | null | undefined | E
28
+ ? ArrayElement<Base> extends Primitive | E
26
29
  ? ArrayElement<Base>[]
27
30
  : Projection<Defined<Selection>, ArrayElement<Base>, E>[]
28
- : Base extends Date | string | number | boolean | null | E
31
+ : Base extends Primitive | E
29
32
  ? // Is primitive and extends undefined
30
33
  Selection extends undefined
31
34
  ? Base | undefined