@baeta/plugin-graphql 0.0.24-75-20230619184544-4493aaa → 0.0.25

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/CHANGELOG.md CHANGED
@@ -1,13 +1,33 @@
1
1
  # @baeta/plugin-graphql
2
2
 
3
- ## 0.0.24-75-20230619184544-4493aaa
3
+ ## 0.0.25
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
8
+
9
+ - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies and builder
10
+
11
+ - [#106](https://github.com/andreisergiu98/baeta/pull/106) [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add compatibility with windows
12
+
13
+ - [#101](https://github.com/andreisergiu98/baeta/pull/101) [`03d1353`](https://github.com/andreisergiu98/baeta/commit/03d1353bcedf211d3b7dcfbe38132e43422742b1) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - ignore extended fields when using object types
14
+
15
+ - Updated dependencies [[`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e)]:
16
+ - @baeta/generator-sdk@0.0.10
17
+ - @baeta/util-path@0.0.2
18
+
19
+ ## 0.0.24
20
+
21
+ ### Patch Changes
22
+
23
+ - [#81](https://github.com/andreisergiu98/baeta/pull/81) [`3ff5e54`](https://github.com/andreisergiu98/baeta/commit/3ff5e54f31cf42ba2264b12309338d6e78710722) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add file transformation function from config
24
+
7
25
  - [#69](https://github.com/andreisergiu98/baeta/pull/69) [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
8
26
 
9
- - Updated dependencies [[`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37)]:
10
- - @baeta/generator-sdk@0.0.9-75-20230619184544-4493aaa
27
+ - [#91](https://github.com/andreisergiu98/baeta/pull/91) [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
28
+
29
+ - Updated dependencies [[`3ff5e54`](https://github.com/andreisergiu98/baeta/commit/3ff5e54f31cf42ba2264b12309338d6e78710722), [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37), [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546)]:
30
+ - @baeta/generator-sdk@0.0.9
11
31
 
12
32
  ## 0.0.23
13
33
 
package/dist/index.cjs CHANGED
@@ -8,7 +8,6 @@ var __export = (target, all) => {
8
8
  var _generatorsdk = require('@baeta/generator-sdk');
9
9
 
10
10
  // lib/codegen.ts
11
-
12
11
  var _core = require('@graphql-codegen/core');
13
12
  var _pluginhelpers = require('@graphql-codegen/plugin-helpers');
14
13
  var _typescript = require('@graphql-codegen/typescript'); var typescriptPlugin = _interopRequireWildcard(_typescript);
@@ -114,9 +113,9 @@ var plugin = async (schema, documents, config) => {
114
113
  var context_default = { plugin };
115
114
 
116
115
  // lib/modules/index.ts
116
+ var _utilpath = require('@baeta/util-path');
117
117
 
118
118
 
119
- var _path = require('path');
120
119
 
121
120
  // lib/modules/builder.ts
122
121
  var _changecaseall = require('change-case-all');
@@ -132,11 +131,14 @@ var _changecaseall = require('change-case-all');
132
131
 
133
132
 
134
133
 
134
+ var _os = require('os');
135
135
  var _parsefilepath = require('parse-filepath'); var _parsefilepath2 = _interopRequireDefault(_parsefilepath);
136
136
  var sep = "/";
137
137
  function collectUsedTypes(doc) {
138
138
  const used = [];
139
- doc.definitions.forEach(findRelated);
139
+ for (const definition of doc.definitions) {
140
+ findRelated(definition);
141
+ }
140
142
  function markAsUsed(type) {
141
143
  pushUnique(used, type);
142
144
  }
@@ -144,28 +146,40 @@ function collectUsedTypes(doc) {
144
146
  if (node.kind === _graphql.Kind.OBJECT_TYPE_DEFINITION || node.kind === _graphql.Kind.OBJECT_TYPE_EXTENSION) {
145
147
  markAsUsed(node.name.value);
146
148
  if (node.fields) {
147
- node.fields.forEach(findRelated);
149
+ for (const field of node.fields) {
150
+ findRelated(field);
151
+ }
148
152
  }
149
153
  if (node.interfaces) {
150
- node.interfaces.forEach(findRelated);
154
+ for (const _interface of node.interfaces) {
155
+ findRelated(_interface);
156
+ }
151
157
  }
152
158
  } else if (node.kind === _graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === _graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION) {
153
159
  markAsUsed(node.name.value);
154
160
  if (node.fields) {
155
- node.fields.forEach(findRelated);
161
+ for (const field of node.fields) {
162
+ findRelated(field);
163
+ }
156
164
  }
157
165
  } else if (node.kind === _graphql.Kind.INTERFACE_TYPE_DEFINITION || node.kind === _graphql.Kind.INTERFACE_TYPE_EXTENSION) {
158
166
  markAsUsed(node.name.value);
159
167
  if (node.fields) {
160
- node.fields.forEach(findRelated);
168
+ for (const field of node.fields) {
169
+ findRelated(field);
170
+ }
161
171
  }
162
172
  if (node.interfaces) {
163
- node.interfaces.forEach(findRelated);
173
+ for (const _interface of node.interfaces) {
174
+ findRelated(_interface);
175
+ }
164
176
  }
165
177
  } else if (node.kind === _graphql.Kind.UNION_TYPE_DEFINITION || node.kind === _graphql.Kind.UNION_TYPE_EXTENSION) {
166
178
  markAsUsed(node.name.value);
167
179
  if (node.types) {
168
- node.types.forEach(findRelated);
180
+ for (const type of node.types) {
181
+ findRelated(type);
182
+ }
169
183
  }
170
184
  } else if (node.kind === _graphql.Kind.ENUM_TYPE_DEFINITION || node.kind === _graphql.Kind.ENUM_TYPE_EXTENSION) {
171
185
  markAsUsed(node.name.value);
@@ -178,7 +192,9 @@ function collectUsedTypes(doc) {
178
192
  } else if (node.kind === _graphql.Kind.FIELD_DEFINITION) {
179
193
  findRelated(resolveTypeNode(node.type));
180
194
  if (node.arguments) {
181
- node.arguments.forEach(findRelated);
195
+ for (const argument of node.arguments) {
196
+ findRelated(argument);
197
+ }
182
198
  }
183
199
  } else if (node.kind === _graphql.Kind.NAMED_TYPE && // Named type
184
200
  !isGraphQLPrimitive(node.name.value)) {
@@ -193,7 +209,7 @@ function collectObjectFieldType(node, fieldDefinition, fieldsMap, fieldTypes) {
193
209
  const field = fieldsMap[fieldDefinition.name.value];
194
210
  const baseName = _pluginhelpers.getBaseType.call(void 0, field.type).name;
195
211
  const isDefaultScalar = _visitorplugincommon.DEFAULT_SCALARS[baseName] != null;
196
- const name = isDefaultScalar ? `Types.Scalars["${baseName}"]` : baseName;
212
+ const name = isDefaultScalar ? `Types.Scalars["${baseName}"]["output"]` : baseName;
197
213
  const type = _visitorplugincommon.wrapTypeWithModifiers.call(void 0, name, field.type, {
198
214
  wrapOptional: (str) => {
199
215
  return `Types.Maybe<${str}>`;
@@ -267,7 +283,7 @@ function buildBlock({ name, lines }) {
267
283
  }
268
284
  return [`${name} {`, ...lines.map(indent(2)), "};"].join("\n");
269
285
  }
270
- var getRelativePath = function(filepath, basePath) {
286
+ var getRelativePath = (filepath, basePath) => {
271
287
  const normalizedFilepath = normalize(filepath);
272
288
  const normalizedBasePath = ensureStartsWithSeparator(
273
289
  normalize(ensureEndsWithSeparator(basePath))
@@ -277,9 +293,9 @@ var getRelativePath = function(filepath, basePath) {
277
293
  };
278
294
  function groupSourcesByModule(sources, basePath) {
279
295
  const grouped = {};
280
- sources.forEach((source) => {
296
+ for (const source of sources) {
281
297
  if (!source.location) {
282
- return;
298
+ continue;
283
299
  }
284
300
  const relativePath = getRelativePath(source.location, basePath);
285
301
  if (relativePath) {
@@ -289,7 +305,7 @@ function groupSourcesByModule(sources, basePath) {
289
305
  }
290
306
  grouped[mod].push(source);
291
307
  }
292
- });
308
+ }
293
309
  return grouped;
294
310
  }
295
311
  function extractModuleDirectory(filepath, basePath) {
@@ -308,6 +324,9 @@ function ensureEndsWithSeparator(path) {
308
324
  return path.endsWith(sep) ? path : path + sep;
309
325
  }
310
326
  function ensureStartsWithSeparator(path) {
327
+ if (_os.platform.call(void 0, ) === "win32") {
328
+ return path;
329
+ }
311
330
  return path.startsWith(".") ? path.replace(/^(..\/)|(.\/)/, "/") : path.startsWith("/") ? path : `/${path}`;
312
331
  }
313
332
  function pushUnique(list, item) {
@@ -323,9 +342,9 @@ function uniqueByKey(left, right, key) {
323
342
  }
324
343
  function createObject(keys, valueFn) {
325
344
  const obj = {};
326
- keys.forEach((key) => {
345
+ for (const key of keys) {
327
346
  obj[key] = valueFn(key);
328
- });
347
+ }
329
348
  return obj;
330
349
  }
331
350
 
@@ -491,7 +510,7 @@ ${contentBody}
491
510
  return `${field}: module.createSubscriptionBuilder<${resultType}, ${parentType}, ${contextType}, ${argumentsType}>("${field}"),`;
492
511
  }
493
512
  function printSubscriptionObjectBuilder() {
494
- const subscriptions = _nullishCoalesce(_optionalChain([picks, 'access', _8 => _8.objects, 'access', _9 => _9["Subscription"], 'optionalAccess', _10 => _10.filter, 'call', _11 => _11(unique)]), () => ( []));
513
+ const subscriptions = _nullishCoalesce(_optionalChain([picks, 'access', _8 => _8.objects, 'access', _9 => _9.Subscription, 'optionalAccess', _10 => _10.filter, 'call', _11 => _11(unique)]), () => ( []));
495
514
  if (subscriptions.length === 0) {
496
515
  return "";
497
516
  }
@@ -562,15 +581,16 @@ ${body}
562
581
  return records[typeName].filter(unique).map(withQuotes).join(" | ");
563
582
  }
564
583
  function printTypeBody(typeName) {
565
- const coreType = `${importNamespace}.${baseVisitor.convertName(typeName, {
584
+ const normalizedTypeName = baseVisitor.convertName(typeName, {
566
585
  useTypesSuffix: true,
567
586
  useTypesPrefix: true
568
- })}`;
587
+ });
588
+ const coreType = `${importNamespace}.${normalizedTypeName}`;
569
589
  if (external.enums.includes(typeName) || external.objects.includes(typeName)) {
570
590
  if (schema && _graphql.isScalarType.call(void 0, schema.getType(typeName))) {
571
591
  return `${importNamespace}.Scalars['${typeName}']`;
572
592
  }
573
- return coreType;
593
+ return `Pick<${coreType}, ${importNamespace}.DefinedFieldsWithoutExtensions["${normalizedTypeName}"]>`;
574
594
  }
575
595
  if (defined.enums.includes(typeName) && picks.enums[typeName]) {
576
596
  return `DefinedEnumValues['${typeName}']`;
@@ -584,7 +604,10 @@ ${body}
584
604
  if (defined.inputs.includes(typeName) && picks.inputs[typeName]) {
585
605
  return `Pick<${coreType}, DefinedInputFields['${typeName}']>`;
586
606
  }
587
- return coreType;
607
+ if (_graphql.isScalarType.call(void 0, _optionalChain([schema, 'optionalAccess', _12 => _12.getType, 'call', _13 => _13(typeName)]))) {
608
+ return coreType;
609
+ }
610
+ return `Pick<${coreType}, ${importNamespace}.DefinedFieldsWithoutExtensions["${normalizedTypeName}"]>`;
588
611
  }
589
612
  function printExportType(typeName) {
590
613
  return `export type ${encapsulateTypeName(typeName)} = ${printTypeBody(typeName)};`;
@@ -595,9 +618,9 @@ ${body}
595
618
  if (!picksObj[name2]) {
596
619
  picksObj[name2] = [];
597
620
  }
598
- node.fields.forEach((field) => {
621
+ for (const field of node.fields) {
599
622
  picksObj[name2].push(field.name.value);
600
- });
623
+ }
601
624
  }
602
625
  }
603
626
  function collectValuesFromEnum(node) {
@@ -606,9 +629,9 @@ ${body}
606
629
  if (!picks.enums[name2]) {
607
630
  picks.enums[name2] = [];
608
631
  }
609
- node.values.forEach((field) => {
632
+ for (const field of node.values) {
610
633
  picks.enums[name2].push(field.name.value);
611
- });
634
+ }
612
635
  }
613
636
  }
614
637
  function collectTypeDefinition(node) {
@@ -684,10 +707,10 @@ ${body}
684
707
  return type;
685
708
  }
686
709
  function getResultType(type, field) {
687
- return _optionalChain([fieldTypes, 'optionalAccess', _12 => _12[type], 'optionalAccess', _13 => _13[field]]) || "{}";
710
+ return _optionalChain([fieldTypes, 'optionalAccess', _14 => _14[type], 'optionalAccess', _15 => _15[field]]) || "{}";
688
711
  }
689
712
  function getArgsType(type, field) {
690
- const hasArgs = _nullishCoalesce(_optionalChain([fieldArguments, 'optionalAccess', _14 => _14[type], 'optionalAccess', _15 => _15[field]]), () => ( false));
713
+ const hasArgs = _nullishCoalesce(_optionalChain([fieldArguments, 'optionalAccess', _16 => _16[type], 'optionalAccess', _17 => _17[field]]), () => ( false));
691
714
  if (!hasArgs) {
692
715
  return "{}";
693
716
  }
@@ -704,31 +727,34 @@ var preset = {
704
727
  buildGeneratesSection: (options) => {
705
728
  const { baseOutputDir } = options;
706
729
  const { baseTypesPath, extensionsPath, encapsulateModuleTypes } = options.presetConfig;
707
- const requireRootResolvers = _visitorplugincommon.getConfigValue.call(void 0, _optionalChain([options, 'optionalAccess', _16 => _16.presetConfig, 'access', _17 => _17.requireRootResolvers]), false);
708
- const cwd = _path.resolve.call(void 0, options.presetConfig.cwd || process.cwd());
730
+ const requireRootResolvers = _visitorplugincommon.getConfigValue.call(void 0, _optionalChain([options, 'optionalAccess', _18 => _18.presetConfig, 'access', _19 => _19.requireRootResolvers]), false);
731
+ const cwd = _utilpath.resolve.call(void 0, options.presetConfig.cwd || process.cwd());
709
732
  const importTypesNamespace = options.presetConfig.importTypesNamespace || "Types";
710
733
  if (!baseTypesPath) {
711
734
  throw new Error(
712
735
  `Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`
713
736
  );
714
737
  }
715
- if (!_optionalChain([options, 'access', _18 => _18.schemaAst, 'optionalAccess', _19 => _19.extensions, 'access', _20 => _20.sources])) {
738
+ if (!_optionalChain([options, 'access', _20 => _20.schemaAst, 'optionalAccess', _21 => _21.extensions, 'access', _22 => _22.sources])) {
716
739
  throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
717
740
  }
718
- const extensions = _optionalChain([options, 'access', _21 => _21.schemaAst, 'optionalAccess', _22 => _22.extensions]);
719
- const sources = _nullishCoalesce(_optionalChain([extensions, 'optionalAccess', _23 => _23.extendedSources]), () => ( []));
741
+ const extensions = _optionalChain([options, 'access', _23 => _23.schemaAst, 'optionalAccess', _24 => _24.extensions]);
742
+ const sources = _nullishCoalesce(_optionalChain([extensions, 'optionalAccess', _25 => _25.extendedSources]), () => ( []));
720
743
  const sourcesByModuleMap = groupSourcesByModule(sources, baseOutputDir);
721
744
  const modules = Object.keys(sourcesByModuleMap);
722
745
  const baseVisitor = new (0, _visitorplugincommon.BaseVisitor)(options.config, {});
723
746
  const { fieldTypes, fieldArguments } = collectObjectFieldTypesAndArguments(options.schemaAst);
724
747
  const baseOutput = {
725
- filename: _path.resolve.call(void 0, cwd, baseOutputDir, baseTypesPath),
748
+ filename: _utilpath.resolve.call(void 0, cwd, baseOutputDir, baseTypesPath),
726
749
  schema: options.schema,
727
750
  documents: options.documents,
728
751
  plugins: [
729
752
  ...options.plugins,
730
753
  {
731
754
  "modules-exported-scalars": {}
755
+ },
756
+ {
757
+ "modules-exported-picks": {}
732
758
  }
733
759
  ],
734
760
  pluginMap: {
@@ -744,6 +770,35 @@ var preset = {
744
770
  return null;
745
771
  }).filter(Boolean).join("\n");
746
772
  }
773
+ },
774
+ "modules-exported-picks": {
775
+ plugin: (schema) => {
776
+ const typePicks = [];
777
+ for (const moduleName of modules) {
778
+ const sources2 = sourcesByModuleMap[moduleName];
779
+ const documents = sources2.map((source) => source.document);
780
+ const moduleDocument = _graphql.concatAST.call(void 0, documents);
781
+ const types = moduleDocument.definitions.filter(
782
+ (def) => def.kind === "ObjectTypeDefinition"
783
+ );
784
+ for (const type of types) {
785
+ const name = type.name.value;
786
+ if (name === "Query" || name === "Mutation" || name === "Subscription") {
787
+ continue;
788
+ }
789
+ const fields = _nullishCoalesce(type.fields, () => ( []));
790
+ if (fields.length === 0) {
791
+ continue;
792
+ }
793
+ const fieldNames = fields.map((f) => `"${f.name.value}"`).join(" | ");
794
+ typePicks.push(` ${name}: ${fieldNames};`);
795
+ }
796
+ }
797
+ return `
798
+ export type DefinedFieldsWithoutExtensions = {
799
+ ${typePicks.join("\n")}
800
+ };`;
801
+ }
747
802
  }
748
803
  },
749
804
  config: {
@@ -755,10 +810,10 @@ var preset = {
755
810
  const baseTypesFilename = baseTypesPath.replace(/\.(js|ts|d.ts)$/, "");
756
811
  const baseTypesDir = stripFilename(baseOutput.filename);
757
812
  const outputs = modules.map((moduleName) => {
758
- const filename = _path.resolve.call(void 0, cwd, baseOutputDir, moduleName, options.presetConfig.filename);
813
+ const filename = _utilpath.resolve.call(void 0, cwd, baseOutputDir, moduleName, options.presetConfig.filename);
759
814
  const dirpath = stripFilename(filename);
760
- const relativePath = _path.relative.call(void 0, dirpath, baseTypesDir);
761
- const importPath = options.presetConfig.importBaseTypesFrom || normalize(_path.join.call(void 0, relativePath, baseTypesFilename));
815
+ const relativePath = _utilpath.relative.call(void 0, dirpath, baseTypesDir);
816
+ const importPath = options.presetConfig.importBaseTypesFrom || normalize(_utilpath.join.call(void 0, relativePath, baseTypesFilename));
762
817
  const sources2 = sourcesByModuleMap[moduleName];
763
818
  const documents = sources2.map((source) => source.document);
764
819
  const moduleDocument = _graphql.concatAST.call(void 0, documents);
@@ -789,9 +844,9 @@ var preset = {
789
844
  fieldArguments,
790
845
  extensionsPath,
791
846
  rootTypes: [
792
- _optionalChain([schema, 'access', _24 => _24.getQueryType, 'call', _25 => _25(), 'optionalAccess', _26 => _26.name]) || "",
793
- _optionalChain([schema, 'access', _27 => _27.getMutationType, 'call', _28 => _28(), 'optionalAccess', _29 => _29.name]) || "",
794
- _optionalChain([schema, 'access', _30 => _30.getSubscriptionType, 'call', _31 => _31(), 'optionalAccess', _32 => _32.name]) || ""
847
+ _optionalChain([schema, 'access', _26 => _26.getQueryType, 'call', _27 => _27(), 'optionalAccess', _28 => _28.name]) || "",
848
+ _optionalChain([schema, 'access', _29 => _29.getMutationType, 'call', _30 => _30(), 'optionalAccess', _31 => _31.name]) || "",
849
+ _optionalChain([schema, 'access', _32 => _32.getSubscriptionType, 'call', _33 => _33(), 'optionalAccess', _34 => _34.name]) || ""
795
850
  ].filter(Boolean)
796
851
  })
797
852
  }
@@ -859,7 +914,10 @@ async function generate(options) {
859
914
  ...output,
860
915
  cache
861
916
  });
862
- return new (0, _generatorsdk.File)(output.filename, result2, "graphql");
917
+ return {
918
+ filename: output.filename,
919
+ content: result2
920
+ };
863
921
  });
864
922
  return Promise.all(promises);
865
923
  }
@@ -879,8 +937,10 @@ function graphqlPlugin() {
879
937
  watcher.on("delete", handleChange);
880
938
  },
881
939
  generate: async (ctx, next) => {
882
- const files = await generate(ctx.generatorOptions);
883
- ctx.fileManager.add(...files);
940
+ const items = await generate(ctx.generatorOptions);
941
+ for (const item of items) {
942
+ ctx.fileManager.createAndAdd(item.filename, item.content, "graphql");
943
+ }
884
944
  return next();
885
945
  }
886
946
  });