@avantstay/graphql-ts-client 11.0.0-beta.1 → 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.
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.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: "11.0.0-beta.1",
490
+ version: "11.0.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
  });
@@ -866,7 +866,7 @@ function _fetchIntrospection() {
866
866
  switch(_state.label){
867
867
  case 0:
868
868
  endpoint = param.endpoint, headers = param.headers;
869
- introspectionCacheFileName = "gql-ts-client__introspection__".concat((0, import_lodash.kebabCase)(endpoint), ".json");
869
+ introspectionCacheFileName = "gql-ts-client__introspection__".concat((0, import_kebabCase.default)(endpoint), ".json");
870
870
  introspectionCacheFilePath = import_path.default.resolve(tempDir, introspectionCacheFileName);
871
871
  loadedFromCache = false;
872
872
  return [
@@ -877,7 +877,7 @@ function _fetchIntrospection() {
877
877
  headers: _objectSpread({
878
878
  "Content-Type": "application/json"
879
879
  }, headers)
880
- }).catch(function() {
880
+ }).catch(function(e) {
881
881
  var errorMessage = "The GraphQL introspection request failed (".concat(endpoint, ")");
882
882
  if (fs.existsSync(introspectionCacheFilePath)) {
883
883
  var cachedSchema = JSON.parse(fs.readFileSync(introspectionCacheFilePath, {
@@ -889,6 +889,7 @@ function _fetchIntrospection() {
889
889
  data: cachedSchema
890
890
  };
891
891
  } else {
892
+ console.error(e);
892
893
  return Promise.reject(errorMessage);
893
894
  }
894
895
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avantstay/graphql-ts-client",
3
- "version": "11.0.0-beta.1",
3
+ "version": "11.0.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
@@ -34,21 +34,21 @@ export interface FailingQueryArgs {
34
34
  * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
35
35
  */
36
36
 
37
- export interface Image {
38
- url?: string
39
- alt?: string
37
+ export interface Book {
38
+ title?: string
39
+ author?: string
40
+ type?: BookType
41
+ dateCreated?: ISODate
42
+ sequence?: BookSequence
40
43
  }
41
44
 
42
45
  /**
43
46
  * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
44
47
  */
45
48
 
46
- export interface Book {
47
- title?: string
48
- author?: string
49
- type?: BookType
50
- dateCreated?: ISODate
51
- images?: Image[]
49
+ export interface BookSequence {
50
+ previousBook?: Book
51
+ nextBook?: Book
52
52
  }
53
53
 
54
54
  /**
@@ -83,17 +83,17 @@ export interface Query {
83
83
 
84
84
  // Selection Types
85
85
 
86
- export interface ImageSelection {
87
- url?: boolean
88
- alt?: boolean
89
- }
90
-
91
86
  export interface BookSelection {
92
87
  title?: boolean
93
88
  author?: boolean
94
89
  type?: boolean
95
90
  dateCreated?: boolean
96
- images?: ImageSelection
91
+ sequence?: BookSequenceSelection
92
+ }
93
+
94
+ export interface BookSequenceSelection {
95
+ previousBook?: BookSelection
96
+ nextBook?: BookSelection
97
97
  }
98
98
 
99
99
  export interface BookSearchParamsAllOptionalSelection {
@@ -124,7 +124,7 @@ export declare const myApiClient: {
124
124
  __retry?: boolean
125
125
  __alias?: string
126
126
  } & BookSelection,
127
- Book[],
127
+ DeepRequired<Book[]>,
128
128
  AllEnums
129
129
  >
130
130
  booksWithOptionalParams: Endpoint<
@@ -134,7 +134,7 @@ export declare const myApiClient: {
134
134
  __alias?: string
135
135
  __args?: BooksWithOptionalParamsArgs
136
136
  } & BookSelection,
137
- Book[],
137
+ DeepRequired<Book[]>,
138
138
  AllEnums
139
139
  >
140
140
  booksWithRequiredParams: Endpoint<
@@ -144,7 +144,7 @@ export declare const myApiClient: {
144
144
  __alias?: string
145
145
  __args: BooksWithRequiredParamsArgs
146
146
  } & BookSelection,
147
- Book[],
147
+ DeepRequired<Book[]>,
148
148
  AllEnums
149
149
  >
150
150
  failingQuery: Endpoint<
@@ -67,7 +67,23 @@ const typesTree = {
67
67
  }
68
68
  },
69
69
  Book: {
70
- images: {}
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
+ }
71
87
  }
72
88
  };
73
89
  let verbose = false;
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
 
@@ -499,7 +500,7 @@ async function fetchIntrospection({ endpoint, headers }: FetchIntrospectionOptio
499
500
  },
500
501
  }
501
502
  )
502
- .catch(() => {
503
+ .catch((e) => {
503
504
  const errorMessage = `The GraphQL introspection request failed (${endpoint})`
504
505
  if (fs.existsSync(introspectionCacheFilePath)) {
505
506
  const cachedSchema = JSON.parse(fs.readFileSync(introspectionCacheFilePath, { encoding: 'utf8' }))
@@ -507,6 +508,7 @@ async function fetchIntrospection({ endpoint, headers }: FetchIntrospectionOptio
507
508
  console.warn(`Successfully restored from local cache.`)
508
509
  return { data: cachedSchema }
509
510
  } else {
511
+ console.error(e)
510
512
  return Promise.reject(errorMessage)
511
513
  }
512
514
  })
@@ -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 },