@avantstay/graphql-ts-client 10.7.1 → 10.8.1
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/dist/endpoint.js +8 -3
- package/dist/index.js +7 -6
- package/package.json +1 -1
- package/src/__snapshots__/generateTypescriptClient.test.ts.snap +1 -0
- package/src/__testClient.d.ts +4 -0
- package/src/endpoint.ts +4 -1
- package/src/generateTypescriptClient.ts +5 -3
- package/src/jsonToGraphQLQuery.ts +1 -1
package/dist/endpoint.js
CHANGED
|
@@ -618,7 +618,8 @@ function jsonToGraphQLQuery(param) {
|
|
|
618
618
|
var alias = jsonQuery.__alias;
|
|
619
619
|
var newJsonQuery = cloneDeep((0, import_omit.default)(jsonQuery, [
|
|
620
620
|
"__alias",
|
|
621
|
-
"__headers"
|
|
621
|
+
"__headers",
|
|
622
|
+
"__url"
|
|
622
623
|
]));
|
|
623
624
|
extractVariables({
|
|
624
625
|
jsonQuery: _defineProperty({}, queryName, newJsonQuery),
|
|
@@ -738,11 +739,13 @@ var getApiEndpointCreator = function(apiConfig) {
|
|
|
738
739
|
return function(kind, queryName) {
|
|
739
740
|
var rawEndpoint = function() {
|
|
740
741
|
var _ref = _asyncToGenerator(function(failureMode, jsonQuery) {
|
|
741
|
-
var _jsonQuery___alias, alias, _jsonQuery___retry, shouldRetry, _jsonQuery___headers, requestHeaders, _jsonToGraphQLQuery, query, variables, start, logOptions, responseListenerData, _ref, data, errors, warnings, headers, status, response, error;
|
|
742
|
+
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;
|
|
742
743
|
return __generator(this, function(_state) {
|
|
743
744
|
switch(_state.label){
|
|
744
745
|
case 0:
|
|
746
|
+
clientConfig = apiConfig.getClient();
|
|
745
747
|
alias = (_jsonQuery___alias = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__alias) !== null && _jsonQuery___alias !== void 0 ? _jsonQuery___alias : queryName;
|
|
748
|
+
url = (_jsonQuery___url = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__url) !== null && _jsonQuery___url !== void 0 ? _jsonQuery___url : clientConfig.url;
|
|
746
749
|
shouldRetry = (_jsonQuery___retry = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__retry) !== null && _jsonQuery___retry !== void 0 ? _jsonQuery___retry : true;
|
|
747
750
|
requestHeaders = (_jsonQuery___headers = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__headers) !== null && _jsonQuery___headers !== void 0 ? _jsonQuery___headers : {};
|
|
748
751
|
_jsonToGraphQLQuery = jsonToGraphQLQuery({
|
|
@@ -779,7 +782,9 @@ var getApiEndpointCreator = function(apiConfig) {
|
|
|
779
782
|
shouldRetry: shouldRetry,
|
|
780
783
|
failureMode: failureMode,
|
|
781
784
|
queryName: alias,
|
|
782
|
-
client:
|
|
785
|
+
client: _objectSpreadProps(_objectSpread({}, clientConfig), {
|
|
786
|
+
url: url
|
|
787
|
+
}),
|
|
783
788
|
requestHeaders: requestHeaders,
|
|
784
789
|
query: query,
|
|
785
790
|
variables: variables,
|
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
|
|
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.
|
|
490
|
+
version: "10.8.1",
|
|
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,
|
|
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
|
})
|
package/package.json
CHANGED
package/src/__testClient.d.ts
CHANGED
|
@@ -107,6 +107,7 @@ export declare const myApiClient: {
|
|
|
107
107
|
__headers?: { [key: string]: string }
|
|
108
108
|
__retry?: boolean
|
|
109
109
|
__alias?: string
|
|
110
|
+
__url?: string
|
|
110
111
|
} & BookSelection,
|
|
111
112
|
DeepRequired<Book[]>,
|
|
112
113
|
AllEnums
|
|
@@ -116,6 +117,7 @@ export declare const myApiClient: {
|
|
|
116
117
|
__headers?: { [key: string]: string }
|
|
117
118
|
__retry?: boolean
|
|
118
119
|
__alias?: string
|
|
120
|
+
__url?: string
|
|
119
121
|
__args?: BooksWithOptionalParamsArgs
|
|
120
122
|
} & BookSelection,
|
|
121
123
|
DeepRequired<Book[]>,
|
|
@@ -126,6 +128,7 @@ export declare const myApiClient: {
|
|
|
126
128
|
__headers?: { [key: string]: string }
|
|
127
129
|
__retry?: boolean
|
|
128
130
|
__alias?: string
|
|
131
|
+
__url?: string
|
|
129
132
|
__args: BooksWithRequiredParamsArgs
|
|
130
133
|
} & BookSelection,
|
|
131
134
|
DeepRequired<Book[]>,
|
|
@@ -136,6 +139,7 @@ export declare const myApiClient: {
|
|
|
136
139
|
__headers?: { [key: string]: string }
|
|
137
140
|
__retry?: boolean
|
|
138
141
|
__alias?: string
|
|
142
|
+
__url?: string
|
|
139
143
|
__args: FailingQueryArgs
|
|
140
144
|
},
|
|
141
145
|
string,
|
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:
|
|
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
|
|
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 },
|