@avantstay/graphql-ts-client 10.7.0 → 10.8.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-4ecbabdf.js';
1
+ import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-85e628f6.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/endpoint.js CHANGED
@@ -603,7 +603,8 @@ function jsonToGraphQLQuery(param) {
603
603
  var alias = jsonQuery.__alias;
604
604
  var newJsonQuery = cloneDeep((0, import_omit.default)(jsonQuery, [
605
605
  "__alias",
606
- "__headers"
606
+ "__headers",
607
+ "__url"
607
608
  ]));
608
609
  extractVariables({
609
610
  jsonQuery: _defineProperty({}, queryName, newJsonQuery),
@@ -723,11 +724,13 @@ var getApiEndpointCreator = function(apiConfig) {
723
724
  return function(kind, queryName) {
724
725
  var rawEndpoint = function() {
725
726
  var _ref = _asyncToGenerator(function(failureMode, jsonQuery) {
726
- var _jsonQuery___alias, alias, _jsonQuery___retry, shouldRetry, _jsonQuery___headers, requestHeaders, _jsonToGraphQLQuery, query, variables, start, logOptions, responseListenerData, _ref, data, errors, warnings, headers, status, response, error;
727
+ var clientConfig, _jsonQuery___alias, alias, _jsonQuery___url, url, _jsonQuery___retry, shouldRetry, _jsonQuery___headers, requestHeaders, _jsonToGraphQLQuery, query, variables, start, logOptions, responseListenerData, _ref, data, errors, warnings, headers, status, response, error;
727
728
  return __generator(this, function(_state) {
728
729
  switch(_state.label){
729
730
  case 0:
731
+ clientConfig = apiConfig.getClient();
730
732
  alias = (_jsonQuery___alias = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__alias) !== null && _jsonQuery___alias !== void 0 ? _jsonQuery___alias : queryName;
733
+ url = (_jsonQuery___url = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__url) !== null && _jsonQuery___url !== void 0 ? _jsonQuery___url : clientConfig.url;
731
734
  shouldRetry = (_jsonQuery___retry = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__retry) !== null && _jsonQuery___retry !== void 0 ? _jsonQuery___retry : true;
732
735
  requestHeaders = (_jsonQuery___headers = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__headers) !== null && _jsonQuery___headers !== void 0 ? _jsonQuery___headers : {};
733
736
  _jsonToGraphQLQuery = jsonToGraphQLQuery({
@@ -764,7 +767,9 @@ var getApiEndpointCreator = function(apiConfig) {
764
767
  shouldRetry: shouldRetry,
765
768
  failureMode: failureMode,
766
769
  queryName: alias,
767
- client: apiConfig.getClient(),
770
+ client: _objectSpreadProps(_objectSpread({}, clientConfig), {
771
+ url: url
772
+ }),
768
773
  requestHeaders: requestHeaders,
769
774
  query: query,
770
775
  variables: variables,
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-4ecbabdf.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-85e628f6.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
@@ -477,7 +477,7 @@ var import_case = __toESM(require("case"));
477
477
  var esbuild = __toESM(require("esbuild"));
478
478
  var fs = __toESM(require("fs"));
479
479
  var import_graphql = require("graphql");
480
- var import_lodash = require("lodash");
480
+ var import_kebabCase = __toESM(require("lodash/kebabCase"));
481
481
  var import_orderBy = __toESM(require("lodash/orderBy"));
482
482
  var import_set = __toESM(require("lodash/set"));
483
483
  var import_md5 = __toESM(require("md5"));
@@ -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.7.0",
490
+ version: "10.8.0",
491
491
  description: "GraphQL Typescript Client Generator",
492
492
  author: "Wellington Guimaraes",
493
493
  license: "MIT",
@@ -639,7 +639,7 @@ function gqlFieldToTypescript(field, param) {
639
639
  selection: false
640
640
  });
641
641
  });
642
- fieldTypeDefinition = "{ __headers?: {[key: string]: string}; __retry?: boolean; __alias?: string; __args".concat(fieldsOnArgs.every(function(arg) {
642
+ fieldTypeDefinition = "{ __headers?: {[key: string]: string}; __retry?: boolean; __alias?: string; __url?: string; __args".concat(fieldsOnArgs.every(function(arg) {
643
643
  return arg.isOptional;
644
644
  }) ? "?" : "", ": { ").concat(fieldsOnArgs.map(function(arg) {
645
645
  return arg.code;
@@ -679,7 +679,7 @@ function gqlEndpointToCode(kind, endpoint, codeOutputType) {
679
679
  selection: true
680
680
  });
681
681
  var argsType = endpoint.args && endpoint.args.length ? getArgsType(endpoint) : null;
682
- var inputType = "{\n __headers?: {[key: string]: string};\n __retry?: boolean;\n __alias?: string;\n ".concat(argsType ? "__args".concat(argsType.optional ? "?" : "", ": ").concat(argsType.alias) : "", "\n }").concat(selectionType ? " & ".concat(selectionType) : "");
682
+ var inputType = "{\n __headers?: {[key: string]: string};\n __retry?: boolean;\n __alias?: string;\n __url?: string;\n ".concat(argsType ? "__args".concat(argsType.optional ? "?" : "", ": ").concat(argsType.alias) : "", "\n }").concat(selectionType ? " & ".concat(selectionType) : "");
683
683
  var outputType = gqlTypeToTypescript(endpoint.type, {
684
684
  required: true
685
685
  });
@@ -867,7 +867,7 @@ function _fetchIntrospection() {
867
867
  switch(_state.label){
868
868
  case 0:
869
869
  endpoint = param.endpoint, headers = param.headers;
870
- introspectionCacheFileName = "gql-ts-client__introspection__".concat((0, import_lodash.kebabCase)(endpoint), ".json");
870
+ introspectionCacheFileName = "gql-ts-client__introspection__".concat((0, import_kebabCase.default)(endpoint), ".json");
871
871
  introspectionCacheFilePath = import_path.default.resolve(tempDir, introspectionCacheFileName);
872
872
  loadedFromCache = false;
873
873
  return [
@@ -878,7 +878,7 @@ function _fetchIntrospection() {
878
878
  headers: _objectSpread({
879
879
  "Content-Type": "application/json"
880
880
  }, headers)
881
- }).catch(function() {
881
+ }).catch(function(e) {
882
882
  var errorMessage = "The GraphQL introspection request failed (".concat(endpoint, ")");
883
883
  if (fs.existsSync(introspectionCacheFilePath)) {
884
884
  var cachedSchema = JSON.parse(fs.readFileSync(introspectionCacheFilePath, {
@@ -890,6 +890,7 @@ function _fetchIntrospection() {
890
890
  data: cachedSchema
891
891
  };
892
892
  } else {
893
+ console.error(e);
893
894
  return Promise.reject(errorMessage);
894
895
  }
895
896
  })
@@ -0,0 +1,69 @@
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;
67
+ }
68
+
69
+ 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.7.0",
3
+ "version": "10.8.0",
4
4
  "description": "GraphQL Typescript Client Generator",
5
5
  "author": "Wellington Guimaraes",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@ __export(exports, {
29
29
  client: () => client,
30
30
  default: () => stdin_default
31
31
  });
32
- var import_endpoint = __toModule(require("../dist/endpoint"));
32
+ var import_endpoint = __toModule(require("./endpoint"));
33
33
  const formatGraphQL = (query) => query;
34
34
  const typesTree = {};
35
35
  let verbose = false;
@@ -79,7 +79,7 @@ var stdin_default = client;
79
79
  ",
80
80
  "typings": "// noinspection TypeScriptUnresolvedVariable, ES6UnusedImports, JSUnusedLocalSymbols, TypeScriptCheckImport
81
81
  import { DeepRequired } from "ts-essentials"
82
- import { Maybe, IResponseListener, Endpoint } from "../dist"
82
+ import { Maybe, IResponseListener, Endpoint } from "."
83
83
 
84
84
  // Scalars
85
85
  export type IDate = string | Date
@@ -119,6 +119,7 @@ export declare const client: {
119
119
  __headers?: { [key: string]: string }
120
120
  __retry?: boolean
121
121
  __alias?: string
122
+ __url?: string
122
123
  },
123
124
  string,
124
125
  AllEnums
@@ -0,0 +1,152 @@
1
+ // noinspection TypeScriptUnresolvedVariable, ES6UnusedImports, JSUnusedLocalSymbols, TypeScriptCheckImport
2
+ import { DeepRequired } from "ts-essentials"
3
+ import { Maybe, IResponseListener, Endpoint } from "."
4
+
5
+ // Scalars
6
+ export type IDate = string | Date
7
+ export declare type ISODate = IDate
8
+
9
+ // Enums
10
+
11
+ export declare enum BookType {
12
+ dolor = "DOLOR",
13
+ ipsum = "IPSUM",
14
+ sit = "SIT",
15
+ }
16
+
17
+ type AllEnums = BookType
18
+
19
+ // Args
20
+ export interface BooksWithoutParamsArgs {}
21
+ export interface BooksWithOptionalParamsArgs {
22
+ params?: BookSearchParamsAllOptional
23
+ }
24
+ export interface BooksWithRequiredParamsArgs {
25
+ params: BookSearchParamsSomeRequired
26
+ }
27
+ export interface FailingQueryArgs {
28
+ id: string
29
+ }
30
+
31
+ // Input/Output Types
32
+
33
+ /**
34
+ * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
35
+ */
36
+
37
+ export interface Book {
38
+ title?: string
39
+ author?: string
40
+ type?: BookType
41
+ dateCreated?: ISODate
42
+ }
43
+
44
+ /**
45
+ * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
46
+ */
47
+
48
+ export interface BookSearchParamsAllOptional {
49
+ title?: string
50
+ author?: string
51
+ createdAfter?: ISODate
52
+ }
53
+
54
+ /**
55
+ * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
56
+ */
57
+
58
+ export interface BookSearchParamsSomeRequired {
59
+ title: string
60
+ author?: string
61
+ }
62
+
63
+ /**
64
+ * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
65
+ */
66
+
67
+ export interface Query {
68
+ booksWithoutParams?: Book[]
69
+ booksWithOptionalParams?: Book[]
70
+ booksWithRequiredParams?: Book[]
71
+ failingQuery?: string
72
+ }
73
+
74
+ // Selection Types
75
+
76
+ export interface BookSelection {
77
+ title?: boolean
78
+ author?: boolean
79
+ type?: boolean
80
+ dateCreated?: boolean
81
+ }
82
+
83
+ export interface BookSearchParamsAllOptionalSelection {
84
+ title?: boolean
85
+ author?: boolean
86
+ createdAfter?: boolean
87
+ }
88
+
89
+ export interface BookSearchParamsSomeRequiredSelection {
90
+ title?: boolean
91
+ author?: boolean
92
+ }
93
+
94
+ export declare const myApiClient: {
95
+ addResponseListener: (listener: IResponseListener) => void
96
+ setHeader: (key: string, value: string) => void
97
+ setHeaders: (newHeaders: { [k: string]: string }) => void
98
+ setUrl: (url: string) => void
99
+ setRetryConfig: (options: {
100
+ max: number
101
+ waitBeforeRetry?: number
102
+ before?: IResponseListener
103
+ }) => void
104
+ queries: {
105
+ booksWithoutParams: Endpoint<
106
+ {
107
+ __headers?: { [key: string]: string }
108
+ __retry?: boolean
109
+ __alias?: string
110
+ __url?: string
111
+ } & BookSelection,
112
+ DeepRequired<Book[]>,
113
+ AllEnums
114
+ >
115
+ booksWithOptionalParams: Endpoint<
116
+ {
117
+ __headers?: { [key: string]: string }
118
+ __retry?: boolean
119
+ __alias?: string
120
+ __url?: string
121
+ __args?: BooksWithOptionalParamsArgs
122
+ } & BookSelection,
123
+ DeepRequired<Book[]>,
124
+ AllEnums
125
+ >
126
+ booksWithRequiredParams: Endpoint<
127
+ {
128
+ __headers?: { [key: string]: string }
129
+ __retry?: boolean
130
+ __alias?: string
131
+ __url?: string
132
+ __args: BooksWithRequiredParamsArgs
133
+ } & BookSelection,
134
+ DeepRequired<Book[]>,
135
+ AllEnums
136
+ >
137
+ failingQuery: Endpoint<
138
+ {
139
+ __headers?: { [key: string]: string }
140
+ __retry?: boolean
141
+ __alias?: string
142
+ __url?: string
143
+ __args: FailingQueryArgs
144
+ },
145
+ string,
146
+ AllEnums
147
+ >
148
+ }
149
+ mutations: {}
150
+ }
151
+
152
+ export default myApiClient
@@ -0,0 +1,110 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ __markAsModule(target);
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __reExport = (target, module2, desc) => {
14
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
15
+ for (let key of __getOwnPropNames(module2))
16
+ if (!__hasOwnProp.call(target, key) && key !== "default")
17
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
18
+ }
19
+ return target;
20
+ };
21
+ var __toModule = (module2) => {
22
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
23
+ };
24
+ __export(exports, {
25
+ BookType: () => BookType,
26
+ default: () => stdin_default,
27
+ myApiClient: () => myApiClient
28
+ });
29
+ var import_endpoint = __toModule(require("./endpoint"));
30
+ var import_standalone = __toModule(require("prettier/standalone"));
31
+ var import_parser_graphql = __toModule(require("prettier/parser-graphql"));
32
+ const formatGraphQL = (query) => (0, import_standalone.format)(query, { parser: "graphql", plugins: [import_parser_graphql.default] });
33
+ const BookType = {
34
+ dolor: "DOLOR",
35
+ ipsum: "IPSUM",
36
+ sit: "SIT"
37
+ };
38
+ const typesTree = {
39
+ Query: {
40
+ get booksWithOptionalParams() {
41
+ return {
42
+ __args: {
43
+ params: "BookSearchParamsAllOptional!"
44
+ }
45
+ };
46
+ },
47
+ get booksWithRequiredParams() {
48
+ return {
49
+ __args: {
50
+ params: "BookSearchParamsSomeRequired!"
51
+ }
52
+ };
53
+ },
54
+ get failingQuery() {
55
+ return {
56
+ __args: {
57
+ id: "String!"
58
+ }
59
+ };
60
+ },
61
+ booksWithoutParams: {}
62
+ }
63
+ };
64
+ let verbose = false;
65
+ let headers = {};
66
+ let url = "http://localhost:4123/graphql";
67
+ let retryConfig = {
68
+ max: 0,
69
+ before: void 0,
70
+ waitBeforeRetry: 0
71
+ };
72
+ let responseListeners = [];
73
+ let errorsParser = void 0;
74
+ let apiEndpoint = (0, import_endpoint.getApiEndpointCreator)({
75
+ getClient: () => ({ url, headers, retryConfig }),
76
+ responseListeners,
77
+ maxAge: 3e4,
78
+ verbose,
79
+ typesTree,
80
+ formatGraphQL,
81
+ errorsParser
82
+ });
83
+ const myApiClient = {
84
+ addResponseListener: (listener) => responseListeners.push(listener),
85
+ setHeader: (key, value) => {
86
+ headers[key] = value;
87
+ },
88
+ setHeaders: (newHeaders) => {
89
+ headers = newHeaders;
90
+ },
91
+ setRetryConfig: (options) => {
92
+ if (!Number.isInteger(options.max) || options.max < 0) {
93
+ throw new Error("retryOptions.max should be a non-negative integer");
94
+ }
95
+ retryConfig = {
96
+ max: options.max,
97
+ waitBeforeRetry: options.waitBeforeRetry,
98
+ before: options.before
99
+ };
100
+ },
101
+ setUrl: (_url) => url = _url,
102
+ queries: {
103
+ booksWithoutParams: apiEndpoint("query", "booksWithoutParams"),
104
+ booksWithOptionalParams: apiEndpoint("query", "booksWithOptionalParams"),
105
+ booksWithRequiredParams: apiEndpoint("query", "booksWithRequiredParams"),
106
+ failingQuery: apiEndpoint("query", "failingQuery")
107
+ },
108
+ mutations: {}
109
+ };
110
+ var stdin_default = myApiClient;
package/src/endpoint.ts CHANGED
@@ -32,7 +32,10 @@ export const getApiEndpointCreator =
32
32
  headers: any
33
33
  status: any
34
34
  }> => {
35
+ const clientConfig = apiConfig.getClient()
36
+
35
37
  const alias = (jsonQuery as any)?.__alias ?? queryName
38
+ const url = (jsonQuery as any)?.__url ?? clientConfig.url
36
39
  const shouldRetry = (jsonQuery as any)?.__retry ?? true
37
40
  const requestHeaders = (jsonQuery as any)?.__headers ?? {}
38
41
  const { query, variables } = jsonToGraphQLQuery({ kind, queryName, jsonQuery, typesTree: apiConfig.typesTree })
@@ -58,7 +61,7 @@ export const getApiEndpointCreator =
58
61
  shouldRetry,
59
62
  failureMode,
60
63
  queryName: alias,
61
- client: apiConfig.getClient(),
64
+ client: {...clientConfig, url },
62
65
  requestHeaders,
63
66
  query,
64
67
  variables,
@@ -17,7 +17,7 @@ import {
17
17
  IntrospectionType,
18
18
  Source,
19
19
  } from 'graphql'
20
- import { kebabCase } from 'lodash'
20
+ import kebabCase from 'lodash/kebabCase'
21
21
  import orderBy from 'lodash/orderBy'
22
22
  import set from 'lodash/set'
23
23
  import md5 from 'md5'
@@ -108,7 +108,7 @@ function gqlFieldToTypescript(
108
108
  })
109
109
  )
110
110
 
111
- fieldTypeDefinition = `{ __headers?: {[key: string]: string}; __retry?: boolean; __alias?: string; __args${
111
+ fieldTypeDefinition = `{ __headers?: {[key: string]: string}; __retry?: boolean; __alias?: string; __url?: string; __args${
112
112
  fieldsOnArgs.every(arg => arg.isOptional) ? '?' : ''
113
113
  }: { ${fieldsOnArgs.map(arg => arg.code).join(', ')} }}${fieldTypeDefinition ? ` & ${fieldTypeDefinition}` : ''}`
114
114
  }
@@ -148,6 +148,7 @@ function gqlEndpointToCode(kind: 'mutation' | 'query', endpoint: IntrospectionFi
148
148
  __headers?: {[key: string]: string};
149
149
  __retry?: boolean;
150
150
  __alias?: string;
151
+ __url?: string;
151
152
  ${argsType ? `__args${argsType.optional ? '?' : ''}: ${argsType.alias}` : ''}
152
153
  }${selectionType ? ` & ${selectionType}` : ''}`
153
154
 
@@ -500,7 +501,7 @@ async function fetchIntrospection({ endpoint, headers }: FetchIntrospectionOptio
500
501
  },
501
502
  }
502
503
  )
503
- .catch(() => {
504
+ .catch((e) => {
504
505
  const errorMessage = `The GraphQL introspection request failed (${endpoint})`
505
506
  if (fs.existsSync(introspectionCacheFilePath)) {
506
507
  const cachedSchema = JSON.parse(fs.readFileSync(introspectionCacheFilePath, { encoding: 'utf8' }))
@@ -508,6 +509,7 @@ async function fetchIntrospection({ endpoint, headers }: FetchIntrospectionOptio
508
509
  console.warn(`Successfully restored from local cache.`)
509
510
  return { data: cachedSchema }
510
511
  } else {
512
+ console.error(e)
511
513
  return Promise.reject(errorMessage)
512
514
  }
513
515
  })
@@ -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 },