@avantstay/graphql-ts-client 11.0.0 → 12.0.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/index.js CHANGED
@@ -477,9 +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_kebabCase = __toESM(require("lodash/kebabCase"));
481
- var import_orderBy = __toESM(require("lodash/orderBy"));
482
- var import_set = __toESM(require("lodash/set"));
480
+ var import_lodash = require("lodash");
483
481
  var import_md5 = __toESM(require("md5"));
484
482
  var import_os = __toESM(require("os"));
485
483
  var import_path = __toESM(require("path"));
@@ -487,65 +485,52 @@ var prettier = __toESM(require("prettier"));
487
485
  // package.json
488
486
  var package_default = {
489
487
  name: "@avantstay/graphql-ts-client",
490
- version: "11.0.0",
488
+ version: "12.0.1",
491
489
  description: "GraphQL Typescript Client Generator",
492
- author: "Wellington Guimaraes",
493
- license: "MIT",
494
- main: "dist/index.js",
495
- typings: "dist/index.d.ts",
496
- scripts: {
497
- build: "tsup src/index.ts src/endpoint.ts --dts",
498
- test: "cross-env GQL_CLIENT_DIST_PATH='.' jest --watch",
499
- prepublishOnly: "yarn build"
500
- },
501
- files: [
502
- "dist",
503
- "src"
504
- ],
505
- engines: {
506
- node: ">=12"
507
- },
490
+ homepage: "https://github.com/avantstay/graphql-ts-client",
508
491
  bugs: {
509
492
  url: "https://github.com/avantstay/graphql-ts-client/issues"
510
493
  },
511
- homepage: "https://github.com/avantstay/graphql-ts-client#readme",
512
494
  repository: {
513
495
  type: "git",
514
496
  url: "git+https://github.com/avantstay/graphql-ts-client.git"
515
497
  },
516
- peerDependencies: {},
517
- prettier: {
518
- trailingComma: "es5",
519
- tabWidth: 2,
520
- proseWrap: "always",
521
- bracketSpacing: true,
522
- jsxBracketSameLine: false,
523
- semi: false,
524
- singleQuote: true,
525
- arrowParens: "avoid",
526
- endOfLine: "lf",
527
- printWidth: 130,
528
- htmlWhitespaceSensitivity: "ignore",
529
- jsxSingleQuote: false
530
- },
531
- module: "dist/graphql-ts-client.esm.js",
532
- "size-limit": [
533
- {
534
- path: "dist/graphql-ts-client.cjs.production.min.js",
535
- limit: "10 KB"
498
+ license: "MIT",
499
+ author: "Wellington Guimaraes",
500
+ contributors: [
501
+ "Felipe Pinheiro <felipe.pinheiro.90@hotmail.com>"
502
+ ],
503
+ exports: {
504
+ ".": {
505
+ import: "./dist/index.mjs",
506
+ require: "./dist/index.js",
507
+ types: "./dist/index.d.ts"
536
508
  },
537
- {
538
- path: "dist/graphql-ts-client.esm.js",
539
- limit: "10 KB"
509
+ "./dist/endpoint": {
510
+ import: "./dist/endpoint.mjs",
511
+ require: "./dist/endpoint.js",
512
+ types: "./dist/endpoint.d.ts"
540
513
  }
514
+ },
515
+ main: "dist/index.js",
516
+ module: "dist/index.mjs",
517
+ typings: "dist/index.d.ts",
518
+ files: [
519
+ "dist",
520
+ "src"
541
521
  ],
522
+ scripts: {
523
+ build: "yarn tsup src/index.ts src/endpoint.ts --dts --format cjs,esm",
524
+ prepublishOnly: "yarn build",
525
+ test: "cross-env GQL_CLIENT_DIST_PATH='.' jest --watch"
526
+ },
542
527
  dependencies: {
543
528
  "@types/md5": "^2.3.2",
544
529
  axios: "^0.24.0",
545
530
  "axios-retry": "^3.2.4",
546
531
  case: "^1.6.3",
547
532
  esbuild: "^0.13.14",
548
- graphql: "^15.6.0",
533
+ graphql: "^16.13.2",
549
534
  lodash: "^4.17.21",
550
535
  md5: "^2.3.0",
551
536
  moize: "^6.1.0",
@@ -574,9 +559,23 @@ var package_default = {
574
559
  tsup: "^6.5.0",
575
560
  typescript: "^4.9.4"
576
561
  },
562
+ peerDependencies: {},
563
+ engines: {
564
+ node: ">=12"
565
+ },
577
566
  publishConfig: {
578
567
  "@avantstay:registry": "https://registry.npmjs.org/"
579
- }
568
+ },
569
+ "size-limit": [
570
+ {
571
+ path: "dist/graphql-ts-client.cjs.production.min.js",
572
+ limit: "10 KB"
573
+ },
574
+ {
575
+ path: "dist/graphql-ts-client.esm.js",
576
+ limit: "10 KB"
577
+ }
578
+ ]
580
579
  };
581
580
  // src/generateTypescriptClient.ts
582
581
  var tempDir = fs.realpathSync(import_os.default.tmpdir());
@@ -691,9 +690,9 @@ function gqlSchemaToCode(gqlType, param) {
691
690
  if (rawKind === "SCALAR") {
692
691
  return outputType === "ts" ? "export declare type ".concat(gqlType.name, " = ").concat(/date/i.test(gqlType.name) ? "IDate" : "string") : "";
693
692
  }
694
- if (rawKind === "ENUM") return outputType === "ts" ? "\n export declare enum ".concat(gqlType.name, " {\n ").concat((0, import_orderBy.default)(gqlType.enumValues, "name").map(function(_) {
693
+ if (rawKind === "ENUM") return outputType === "ts" ? "\n export declare enum ".concat(gqlType.name, " {\n ").concat((0, import_lodash.orderBy)(gqlType.enumValues, "name").map(function(_) {
695
694
  return "".concat(import_case.default.camel(_.name), " = '").concat(_.name, "'");
696
- }).join(",\n "), "\n }") : "export const ".concat(gqlType.name, " = {").concat((0, import_orderBy.default)(gqlType.enumValues, "name").map(function(_) {
695
+ }).join(",\n "), "\n }") : "export const ".concat(gqlType.name, " = {").concat((0, import_lodash.orderBy)(gqlType.enumValues, "name").map(function(_) {
697
696
  return "".concat(import_case.default.camel(_.name), ": '").concat(_.name, "'");
698
697
  }).join(",\n "), "}");
699
698
  var fields = gqlType.fields && gqlType.fields || gqlType.inputFields && gqlType.inputFields || [];
@@ -739,7 +738,7 @@ function getTypesTreeCode(types) {
739
738
  return _.args.forEach(function(a) {
740
739
  var inputType = getGraphQLInputType(a.type);
741
740
  if (inputType) {
742
- (0, import_set.default)(typesTree, "".concat(type.name, ".").concat(_.name, ".__args.").concat(a.name), inputType);
741
+ (0, import_lodash.set)(typesTree, "".concat(type.name, ".").concat(_.name, ".__args.").concat(a.name), inputType);
743
742
  }
744
743
  });
745
744
  });
@@ -748,7 +747,7 @@ function getTypesTreeCode(types) {
748
747
  return t.fields.forEach(function(f) {
749
748
  var outputType = getGraphQLOutputType(f.type);
750
749
  if (outputType) {
751
- (0, import_set.default)(typesTree, "".concat(t.name, ".").concat(f.name, ".__shape"), outputType);
750
+ (0, import_lodash.set)(typesTree, "".concat(t.name, ".").concat(f.name, ".__shape"), outputType);
752
751
  }
753
752
  });
754
753
  });
@@ -773,9 +772,12 @@ function generateClientCode(types, options) {
773
772
  var clientCacheFileName = "gql-ts-client__client__".concat(typesHash, "__").concat(package_default.version, ".json");
774
773
  var clientCacheFilePath = import_path.default.resolve(tempDir, clientCacheFileName);
775
774
  if (!options.skipCache && fs.existsSync(clientCacheFilePath)) {
776
- return JSON.parse(fs.readFileSync(clientCacheFilePath, {
775
+ var output2 = JSON.parse(fs.readFileSync(clientCacheFilePath, {
777
776
  encoding: "utf8"
778
777
  }));
778
+ if (output2.js && output2.mjs && output2.typings) {
779
+ return output2;
780
+ }
779
781
  }
780
782
  var queries = ((_types_find = types.find(function(it) {
781
783
  return it.name === "Query";
@@ -848,6 +850,10 @@ function generateClientCode(types, options) {
848
850
  format: "cjs",
849
851
  loader: "js"
850
852
  }).code,
853
+ mjs: esbuild.transformSync(jsCode, {
854
+ format: "esm",
855
+ loader: "js"
856
+ }).code,
851
857
  typings: prettier.format(typingsCode, {
852
858
  semi: false,
853
859
  parser: "typescript"
@@ -866,7 +872,7 @@ function _fetchIntrospection() {
866
872
  switch(_state.label){
867
873
  case 0:
868
874
  endpoint = param.endpoint, headers = param.headers;
869
- introspectionCacheFileName = "gql-ts-client__introspection__".concat((0, import_kebabCase.default)(endpoint), ".json");
875
+ introspectionCacheFileName = "gql-ts-client__introspection__".concat((0, import_lodash.kebabCase)(endpoint), ".json");
870
876
  introspectionCacheFilePath = import_path.default.resolve(tempDir, introspectionCacheFileName);
871
877
  loadedFromCache = false;
872
878
  return [
@@ -876,21 +882,21 @@ function _fetchIntrospection() {
876
882
  }, {
877
883
  headers: _objectSpread({
878
884
  "Content-Type": "application/json"
879
- }, headers)
885
+ }, headers),
886
+ timeout: 5e3
880
887
  }).catch(function(e) {
881
- var errorMessage = "The GraphQL introspection request failed (".concat(endpoint, ")");
882
888
  if (fs.existsSync(introspectionCacheFilePath)) {
883
889
  var cachedSchema = JSON.parse(fs.readFileSync(introspectionCacheFilePath, {
884
890
  encoding: "utf8"
885
891
  }));
886
892
  loadedFromCache = true;
887
- console.warn("Successfully restored from local cache.");
893
+ console.warn("Successfully restored (".concat(endpoint, ") from local cache."));
888
894
  return {
889
895
  data: cachedSchema
890
896
  };
891
897
  } else {
892
898
  console.error(e);
893
- return Promise.reject(errorMessage);
899
+ return Promise.reject("The GraphQL introspection request failed (".concat(endpoint, ")"));
894
900
  }
895
901
  })
896
902
  ];
@@ -916,7 +922,7 @@ function generateClient(introspectionTypes, _param) {
916
922
  var output = _param.output, restOptions = _objectWithoutProperties(_param, [
917
923
  "output"
918
924
  ]);
919
- var _generateClientCode = generateClientCode(introspectionTypes, restOptions), js = _generateClientCode.js, typings = _generateClientCode.typings;
925
+ var _generateClientCode = generateClientCode(introspectionTypes, restOptions), js = _generateClientCode.js, mjs = _generateClientCode.mjs, typings = _generateClientCode.typings;
920
926
  if (output && typeof output === "string") {
921
927
  var outputDir = import_path.default.dirname(output);
922
928
  if (!fs.existsSync(outputDir)) {
@@ -930,9 +936,13 @@ function generateClient(introspectionTypes, _param) {
930
936
  fs.writeFileSync(output.replace(/(\.(ts|js))?$/, ".js"), js, {
931
937
  encoding: "utf8"
932
938
  });
939
+ fs.writeFileSync(output.replace(/(\.(ts|js))?$/, ".mjs"), mjs, {
940
+ encoding: "utf8"
941
+ });
933
942
  }
934
943
  return {
935
944
  js: js,
945
+ mjs: mjs,
936
946
  typings: typings
937
947
  };
938
948
  }
@@ -973,11 +983,15 @@ function _generateTypescriptClient() {
973
983
  return _generateTypescriptClient.apply(this, arguments);
974
984
  }
975
985
  function generateTypescriptClientFromSDL(SDL, options) {
976
- var _data;
986
+ var _introspectionResult_data;
977
987
  var _options_clientName;
978
988
  console.log("Generating TypeScript client from SDL (name: ".concat((_options_clientName = options.clientName) !== null && _options_clientName !== void 0 ? _options_clientName : "n/a", ")"));
979
989
  var graphqlSchemaObj = (0, import_graphql.buildSchema)(SDL);
980
- var introspectionTypes = (_data = (0, import_graphql.graphqlSync)(graphqlSchemaObj, new import_graphql.Source((0, import_graphql.getIntrospectionQuery)())).data) === null || _data === void 0 ? void 0 : _data.__schema.types;
990
+ var introspectionResult = (0, import_graphql.graphqlSync)({
991
+ schema: graphqlSchemaObj,
992
+ source: (0, import_graphql.getIntrospectionQuery)()
993
+ });
994
+ var introspectionTypes = (_introspectionResult_data = introspectionResult.data) === null || _introspectionResult_data === void 0 ? void 0 : _introspectionResult_data.__schema.types;
981
995
  return generateClient(introspectionTypes, options);
982
996
  }
983
997
  // src/types.ts