@baeta/plugin-graphql 0.0.6 → 0.0.8

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.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/index.cjs +85 -128
  3. package/index.d.ts +4 -12
  4. package/index.js +88 -136
  5. package/package.json +35 -39
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Pampu Andrei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.cjs CHANGED
@@ -31,7 +31,7 @@ __export(graphql_exports, {
31
31
  module.exports = __toCommonJS(graphql_exports);
32
32
  var import_plugin2 = require("@baeta/plugin");
33
33
 
34
- // codegen.ts
34
+ // lib/codegen.ts
35
35
  var import_plugin = require("@baeta/plugin");
36
36
  var import_core = require("@graphql-codegen/core");
37
37
  var import_plugin_helpers4 = require("@graphql-codegen/plugin-helpers");
@@ -175,7 +175,7 @@ function ensureEndsWithSeparator(path2) {
175
175
  return path2.endsWith(sep) ? path2 : path2 + sep;
176
176
  }
177
177
  function ensureStartsWithSeparator(path2) {
178
- return path2.startsWith(".") ? path2.replace(/^(..\/)|(.\/)/, "/") : path2.startsWith("/") ? path2 : "/" + path2;
178
+ return path2.startsWith(".") ? path2.replace(/^(..\/)|(.\/)/, "/") : path2.startsWith("/") ? path2 : `/${path2}`;
179
179
  }
180
180
  function pushUnique(list, item) {
181
181
  if (!list.includes(item)) {
@@ -296,10 +296,11 @@ function buildModule(name, doc, {
296
296
  useTypesPrefix: false,
297
297
  useTypesSuffix: false
298
298
  })} {
299
- ` + (shouldDeclare ? `${indent(2)(imports.join("\n"))}
300
- ` : "") + indent(2)(content) + "\n}";
299
+ ${shouldDeclare ? `${indent(2)(imports.join("\n"))}
300
+ ` : ""}${indent(2)(content)}
301
+ }`;
301
302
  }
302
- return [...!shouldDeclare ? imports : [], content, printFactoryMethod()].filter(Boolean).join("\n");
303
+ return [...shouldDeclare ? [] : imports, content, printFactoryMethod()].filter(Boolean).join("\n");
303
304
  function printMetadata() {
304
305
  return `export namespace ModuleMetadata {
305
306
  export const id = '${name}';
@@ -310,7 +311,7 @@ function buildModule(name, doc, {
310
311
  }
311
312
  function printDefinedFields() {
312
313
  return buildBlock({
313
- name: `interface DefinedFields`,
314
+ name: "interface DefinedFields",
314
315
  lines: [...visited.objects, ...visited.interfaces].map(
315
316
  (typeName) => `${typeName}: ${printPicks(typeName, {
316
317
  ...picks.objects,
@@ -324,17 +325,16 @@ function buildModule(name, doc, {
324
325
  const createModuleFn = `create${name2}Module`;
325
326
  const getModuleFn = `get${name2}Module`;
326
327
  return `
327
- export const ${createModuleFn} = () => Baeta.createModule(ModuleMetadata);
328
+ export const ${createModuleFn} = () => Baeta.createModuleManager(ModuleMetadata);
328
329
  export const ${getModuleFn} = Baeta.createSingletonModule(${createModuleFn});
329
330
  `;
330
331
  }
331
332
  function printObjectFieldResolverBuilder(typeName, field) {
332
333
  const resolverType = `${typeName}Resolvers["${field}"]`;
333
- return `${field}: Baeta.createResolverBuilder<NonNullable<${resolverType}>>("${typeName}", "${field}", options),`;
334
+ return `${field}: Baeta.createResolverBuilder<NonNullable<${resolverType}>>(module, "${typeName}", "${field}"),`;
334
335
  }
335
336
  function printObjectResolverBuilder(typeName, objects) {
336
- var _a;
337
- const fields = ((_a = objects[typeName]) == null ? void 0 : _a.filter(unique).map((field) => printObjectFieldResolverBuilder(typeName, field))) ?? [];
337
+ const fields = objects[typeName]?.filter(unique).map((field) => printObjectFieldResolverBuilder(typeName, field)) ?? [];
338
338
  if (fields.length === 0) {
339
339
  return "";
340
340
  }
@@ -342,26 +342,23 @@ export const ${getModuleFn} = Baeta.createSingletonModule(${createModuleFn});
342
342
  const content2 = `{
343
343
  ${fields.map(indent(2)).join("\n")}
344
344
  }`;
345
- return `${typeName}: Baeta.createResolversBuilder("${typeName}", options, {} as ${resolversType}, ${content2}),`;
345
+ return `${typeName}: Baeta.aggregateResolvers(module, "${typeName}", {} as ${resolversType}, ${content2}),`;
346
346
  }
347
347
  function printSubscriptionFieldBuilder(field) {
348
348
  const resolverType = `SubscriptionResolvers["${field}"]`;
349
- return `${field}: Baeta.createSubscriptionBuilder<${resolverType}>("${field}", options),`;
349
+ return `${field}: Baeta.createSubscriptionBuilder<${resolverType}>(module, "${field}"),`;
350
350
  }
351
351
  function printSubscriptionObjectBuilder() {
352
- var _a;
353
- const subscriptions = ((_a = picks.objects["Subscription"]) == null ? void 0 : _a.filter(unique)) ?? [];
352
+ const subscriptions = picks.objects["Subscription"]?.filter(unique) ?? [];
354
353
  if (subscriptions.length === 0) {
355
354
  return "";
356
355
  }
357
- const fields = subscriptions.map(
358
- (subscription) => printSubscriptionFieldBuilder(subscription)
359
- );
360
- const resolversType = `SubscriptionResolvers`;
356
+ const fields = subscriptions.map((subscription) => printSubscriptionFieldBuilder(subscription));
357
+ const resolversType = "SubscriptionResolvers";
361
358
  const content2 = `{
362
359
  ${fields.map(indent(2)).join("\n")}
363
360
  }`;
364
- return `Subscription: Baeta.createSubscriptionsBuilder(options, {} as ${resolversType}, ${content2}),`;
361
+ return `Subscription: Baeta.aggregateSubscriptions(module, {} as ${resolversType}, ${content2}),`;
365
362
  }
366
363
  function printScalarBuilder() {
367
364
  const scalars = visited.scalars;
@@ -369,7 +366,7 @@ ${fields.map(indent(2)).join("\n")}
369
366
  return "";
370
367
  }
371
368
  const fields = scalars.map(
372
- (scalar) => `${scalar}: Baeta.createScalarBuilder("${scalar}", options),`
369
+ (scalar) => `${scalar}: Baeta.createScalarBuilder(module, "${scalar}"),`
373
370
  );
374
371
  const content2 = fields.map(indent(2)).join("\n");
375
372
  return `Scalar: {
@@ -378,26 +375,20 @@ ${content2}
378
375
  }
379
376
  function printBaetaManager() {
380
377
  const objects = visited.objects.filter((type) => type !== "Subscription").map((typeName) => printObjectResolverBuilder(typeName, picks.objects)).filter(Boolean);
381
- const bodyFields = [
382
- ...objects,
383
- printScalarBuilder(),
384
- printSubscriptionObjectBuilder()
385
- ];
378
+ const bodyFields = [...objects, printScalarBuilder(), printSubscriptionObjectBuilder()];
386
379
  const body = bodyFields.filter(Boolean).map(indent(6)).join("\n");
387
380
  const content2 = `{
388
381
  ${body}
389
382
  }`;
390
383
  return `
391
- export function createManager(options: Baeta.ManagerOptions) {
392
- return Baeta.createManager(options, {}, ${content2});
384
+ export function createManager(module: Baeta.ModuleBuilder) {
385
+ return Baeta.aggregateBuilders(module, {} as Resolvers, ${content2});
393
386
  }`;
394
387
  }
395
388
  function printDefinedEnumValues() {
396
389
  return buildBlock({
397
- name: `interface DefinedEnumValues`,
398
- lines: visited.enums.map(
399
- (typeName) => `${typeName}: ${printPicks(typeName, picks.enums)};`
400
- )
390
+ name: "interface DefinedEnumValues",
391
+ lines: visited.enums.map((typeName) => `${typeName}: ${printPicks(typeName, picks.enums)};`)
401
392
  });
402
393
  }
403
394
  function encapsulateTypeName(typeName) {
@@ -408,7 +399,7 @@ ${body}
408
399
  }
409
400
  function printDefinedInputFields() {
410
401
  return buildBlock({
411
- name: `interface DefinedInputFields`,
402
+ name: "interface DefinedInputFields",
412
403
  lines: visited.inputs.map(
413
404
  (typeName) => `${typeName}: ${printPicks(typeName, picks.inputs)};`
414
405
  )
@@ -450,27 +441,27 @@ ${body}
450
441
  function printResolversType(registry) {
451
442
  const lines = [];
452
443
  for (const kind in registry) {
453
- const k = kind;
454
- if (registry.hasOwnProperty(k) && resolverKeys.includes(k)) {
455
- const types = registry[k];
456
- types.forEach((typeName) => {
457
- if (k === "enums") {
458
- return;
459
- }
460
- if (k === "scalars") {
461
- lines.push(
462
- `${typeName}?: ${encapsulateTypeName(
463
- importNamespace
464
- )}.Resolvers['${typeName}'];`
465
- );
466
- } else {
467
- const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? "" : "?";
468
- lines.push(
469
- `${typeName}${fieldModifier}: ${encapsulateTypeName(typeName)}Resolvers;`
470
- );
471
- }
472
- });
444
+ if (!Object.prototype.hasOwnProperty.call(registry, kind)) {
445
+ continue;
446
+ }
447
+ if (!resolverKeys.includes(kind)) {
448
+ continue;
473
449
  }
450
+ const k = kind;
451
+ const types = registry[k];
452
+ types.forEach((typeName) => {
453
+ if (k === "enums") {
454
+ return;
455
+ }
456
+ if (k === "scalars") {
457
+ lines.push(
458
+ `${typeName}?: ${encapsulateTypeName(importNamespace)}.Resolvers['${typeName}'];`
459
+ );
460
+ } else {
461
+ const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? "" : "?";
462
+ lines.push(`${typeName}${fieldModifier}: ${encapsulateTypeName(typeName)}Resolvers;`);
463
+ }
464
+ });
474
465
  }
475
466
  return buildBlock({
476
467
  name: `export interface ${encapsulateTypeName("Resolvers")}`,
@@ -609,10 +600,7 @@ var preset = {
609
600
  buildGeneratesSection: (options) => {
610
601
  const { baseOutputDir } = options;
611
602
  const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
612
- const requireRootResolvers = (0, import_visitor_plugin_common.getConfigValue)(
613
- options == null ? void 0 : options.presetConfig.requireRootResolvers,
614
- false
615
- );
603
+ const requireRootResolvers = (0, import_visitor_plugin_common.getConfigValue)(options?.presetConfig.requireRootResolvers, false);
616
604
  const cwd = (0, import_path.resolve)(options.presetConfig.cwd || process.cwd());
617
605
  const importTypesNamespace = options.presetConfig.importTypesNamespace || "Types";
618
606
  if (!baseTypesPath) {
@@ -620,14 +608,12 @@ var preset = {
620
608
  `Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`
621
609
  );
622
610
  }
623
- if (!options.schemaAst || !options.schemaAst.extensions.sources) {
611
+ if (!options.schemaAst?.extensions.sources) {
624
612
  throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
625
613
  }
626
- const extensions = options.schemaAst.extensions;
627
- const sourcesByModuleMap = groupSourcesByModule(
628
- extensions.extendedSources,
629
- baseOutputDir
630
- );
614
+ const extensions = options.schemaAst?.extensions;
615
+ const sources = extensions?.extendedSources ?? [];
616
+ const sourcesByModuleMap = groupSourcesByModule(sources, baseOutputDir);
631
617
  const modules = Object.keys(sourcesByModuleMap);
632
618
  const baseVisitor = new import_visitor_plugin_common.BaseVisitor(options.config, {});
633
619
  const baseOutput = {
@@ -664,17 +650,12 @@ var preset = {
664
650
  const baseTypesFilename = baseTypesPath.replace(/\.(js|ts|d.ts)$/, "");
665
651
  const baseTypesDir = stripFilename(baseOutput.filename);
666
652
  const outputs = modules.map((moduleName) => {
667
- const filename = (0, import_path.resolve)(
668
- cwd,
669
- baseOutputDir,
670
- moduleName,
671
- options.presetConfig.filename
672
- );
653
+ const filename = (0, import_path.resolve)(cwd, baseOutputDir, moduleName, options.presetConfig.filename);
673
654
  const dirpath = stripFilename(filename);
674
655
  const relativePath = (0, import_path.relative)(dirpath, baseTypesDir);
675
656
  const importPath = options.presetConfig.importBaseTypesFrom || normalize((0, import_path.join)(relativePath, baseTypesFilename));
676
- const sources = sourcesByModuleMap[moduleName];
677
- const documents = sources.map((source) => source.document);
657
+ const sources2 = sourcesByModuleMap[moduleName];
658
+ const documents = sources2.map((source) => source.document);
678
659
  const moduleDocument = (0, import_graphql3.concatAST)(documents);
679
660
  const shouldDeclare = filename.endsWith(".d.ts");
680
661
  return {
@@ -690,24 +671,21 @@ var preset = {
690
671
  pluginMap: {
691
672
  ...options.pluginMap,
692
673
  "graphql-modules-plugin": {
693
- plugin: (schema) => {
694
- var _a, _b, _c;
695
- return buildModule(moduleName, moduleDocument, {
696
- importNamespace: importTypesNamespace,
697
- importPath,
698
- encapsulate: encapsulateModuleTypes || "namespace",
699
- requireRootResolvers,
700
- shouldDeclare,
701
- schema,
702
- baseVisitor,
703
- useGraphQLModules: false,
704
- rootTypes: [
705
- ((_a = schema.getQueryType()) == null ? void 0 : _a.name) || "",
706
- ((_b = schema.getMutationType()) == null ? void 0 : _b.name) || "",
707
- ((_c = schema.getSubscriptionType()) == null ? void 0 : _c.name) || ""
708
- ].filter(Boolean)
709
- });
710
- }
674
+ plugin: (schema) => buildModule(moduleName, moduleDocument, {
675
+ importNamespace: importTypesNamespace,
676
+ importPath,
677
+ encapsulate: encapsulateModuleTypes || "namespace",
678
+ requireRootResolvers,
679
+ shouldDeclare,
680
+ schema,
681
+ baseVisitor,
682
+ useGraphQLModules: false,
683
+ rootTypes: [
684
+ schema.getQueryType()?.name || "",
685
+ schema.getMutationType()?.name || "",
686
+ schema.getSubscriptionType()?.name || ""
687
+ ].filter(Boolean)
688
+ })
711
689
  }
712
690
  },
713
691
  config: options.config,
@@ -739,10 +717,7 @@ var TypeScriptResolversVisitor = class extends import_visitor_plugin_common2.Bas
739
717
  avoidOptionals: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.avoidOptionals, false),
740
718
  useIndexSignature: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.useIndexSignature, false),
741
719
  wrapFieldDefinitions: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.wrapFieldDefinitions, false),
742
- allowParentTypeOverride: (0, import_visitor_plugin_common2.getConfigValue)(
743
- pluginConfig.allowParentTypeOverride,
744
- false
745
- ),
720
+ allowParentTypeOverride: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.allowParentTypeOverride, false),
746
721
  optionalInfoArgument: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.optionalInfoArgument, false)
747
722
  },
748
723
  schema
@@ -775,9 +750,10 @@ var TypeScriptResolversVisitor = class extends import_visitor_plugin_common2.Bas
775
750
  return `ParentType extends ${parentType} = ${parentType}`;
776
751
  }
777
752
  formatRootResolver(schemaTypeName, resolverType, declarationKind) {
778
- var _a;
779
- const avoidOptionals = ((_a = this.config.avoidOptionals) == null ? void 0 : _a.resolvers) ?? this.config.avoidOptionals === true;
780
- return `${schemaTypeName}${avoidOptionals ? "" : "?"}: ${resolverType}${this.getPunctuation(declarationKind)}`;
753
+ const avoidOptionals = this.config.avoidOptionals?.resolvers ?? this.config.avoidOptionals === true;
754
+ return `${schemaTypeName}${avoidOptionals ? "" : "?"}: ${resolverType}${this.getPunctuation(
755
+ declarationKind
756
+ )}`;
781
757
  }
782
758
  clearOptional(str) {
783
759
  if (str.startsWith("Maybe")) {
@@ -808,9 +784,7 @@ var TypeScriptResolversVisitor = class extends import_visitor_plugin_common2.Bas
808
784
  return ";";
809
785
  }
810
786
  buildEnumResolverContentBlock(node, mappedEnumType) {
811
- const valuesMap = `{ ${(node.values || []).map(
812
- (v) => `${v.name}${this.config.avoidOptionals ? "" : "?"}: any`
813
- ).join(", ")} }`;
787
+ const valuesMap = `{ ${(node.values || []).map((v) => `${v.name}${this.config.avoidOptionals ? "" : "?"}: any`).join(", ")} }`;
814
788
  this._globalDeclarations.add(ENUM_RESOLVERS_SIGNATURE);
815
789
  return `EnumResolverSignature<${valuesMap}, ${mappedEnumType}>`;
816
790
  }
@@ -841,9 +815,7 @@ var plugin = (schema, documents, config) => {
841
815
  const defsToInclude = [];
842
816
  const directiveResolverMappings = {};
843
817
  if (config.directiveResolverMappings) {
844
- for (const [directiveName, mapper] of Object.entries(
845
- config.directiveResolverMappings
846
- )) {
818
+ for (const [directiveName, mapper] of Object.entries(config.directiveResolverMappings)) {
847
819
  const parsedMapper = (0, import_visitor_plugin_common3.parseMapper)(mapper);
848
820
  const capitalizedDirectiveName = capitalize(directiveName);
849
821
  const resolverFnName = `ResolverFn${capitalizedDirectiveName}`;
@@ -863,9 +835,7 @@ export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TCo
863
835
  `${importType} { ${parsedMapper.import} ${parsedMapper.import !== resolverFnName ? `as ${resolverFnName} ` : ""}} from '${parsedMapper.source}';`
864
836
  );
865
837
  }
866
- prepend.push(
867
- `export${config.useTypeImports ? " type" : ""} { ${resolverFnName} };`
868
- );
838
+ prepend.push(`export${config.useTypeImports ? " type" : ""} { ${resolverFnName} };`);
869
839
  } else {
870
840
  defsToInclude.push(
871
841
  `export type ${resolverFnName}<TResult, TParent, TContext, TArgs> = ${parsedMapper.type}`
@@ -875,9 +845,7 @@ export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TCo
875
845
  defsToInclude.push(`${resolverType2} ${resolverFnUsage2};`);
876
846
  } else {
877
847
  defsToInclude.push(resolverWithResolve2);
878
- defsToInclude.push(
879
- `${resolverType2} ${resolverFnUsage2} | ${resolverWithResolveUsage2};`
880
- );
848
+ defsToInclude.push(`${resolverType2} ${resolverFnUsage2} | ${resolverWithResolveUsage2};`);
881
849
  }
882
850
  directiveResolverMappings[directiveName] = resolverTypeName;
883
851
  }
@@ -901,15 +869,15 @@ export type NewStitchingResolver<TResult, TParent, TContext, TArgs> = {
901
869
  selectionSet: string | ((fieldNode: FieldNode) => SelectionSetNode);
902
870
  resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
903
871
  };`;
904
- const stitchingResolverType = `export type StitchingResolver<TResult, TParent, TContext, TArgs> = LegacyStitchingResolver<TResult, TParent, TContext, TArgs> | NewStitchingResolver<TResult, TParent, TContext, TArgs>;`;
872
+ const stitchingResolverType = "export type StitchingResolver<TResult, TParent, TContext, TArgs> = LegacyStitchingResolver<TResult, TParent, TContext, TArgs> | NewStitchingResolver<TResult, TParent, TContext, TArgs>;";
905
873
  const resolverWithResolve = `
906
874
  export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
907
875
  resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
908
876
  };`;
909
- const resolverType = `export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> =`;
910
- const resolverFnUsage = `ResolverFn<TResult, TParent, TContext, TArgs>`;
911
- const resolverWithResolveUsage = `ResolverWithResolve<TResult, TParent, TContext, TArgs>`;
912
- const stitchingResolverUsage = `StitchingResolver<TResult, TParent, TContext, TArgs>`;
877
+ const resolverType = "export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> =";
878
+ const resolverFnUsage = "ResolverFn<TResult, TParent, TContext, TArgs>";
879
+ const resolverWithResolveUsage = "ResolverWithResolve<TResult, TParent, TContext, TArgs>";
880
+ const stitchingResolverUsage = "StitchingResolver<TResult, TParent, TContext, TArgs>";
913
881
  if (visitor.hasFederation()) {
914
882
  if (visitor.config.wrapFieldDefinitions) {
915
883
  defsToInclude.push(`export type UnwrappedObject<T> = {
@@ -943,7 +911,7 @@ export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
943
911
  stitchingResolverType,
944
912
  resolverType,
945
913
  ` | ${resolverFnUsage}`,
946
- config.makeResolverTypeCallable ? `` : ` | ${resolverWithResolveUsage}`,
914
+ config.makeResolverTypeCallable ? "" : ` | ${resolverWithResolveUsage}`,
947
915
  ` | ${stitchingResolverUsage};`
948
916
  ].join("\n")
949
917
  );
@@ -985,9 +953,7 @@ export type ResolverFn<TResult, TParent, TContext, TArgs> = (
985
953
  `${importType} { ${parsedMapper.import} ${parsedMapper.import !== "SubscriptionResolver" ? "as SubscriptionResolver " : ""}} from '${parsedMapper.source}';`
986
954
  );
987
955
  }
988
- prepend.push(
989
- `export${config.useTypeImports ? " type" : ""} { SubscriptionResolver };`
990
- );
956
+ prepend.push(`export${config.useTypeImports ? " type" : ""} { SubscriptionResolver };`);
991
957
  } else {
992
958
  prepend.push(
993
959
  `export type SubscriptionResolver<TResult, TKey extends string, TParent = {}, TContext = {}, TArgs = {}> = ${parsedMapper.type}`
@@ -1055,13 +1021,7 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
1055
1021
  `;
1056
1022
  const resolversTypeMapping = visitor.buildResolversTypes();
1057
1023
  const resolversParentTypeMapping = visitor.buildResolversParentTypes();
1058
- const {
1059
- getRootResolver,
1060
- getAllDirectiveResolvers,
1061
- mappersImports,
1062
- unusedMappers,
1063
- hasScalars
1064
- } = visitor;
1024
+ const { getRootResolver, getAllDirectiveResolvers, mappersImports, unusedMappers, hasScalars } = visitor;
1065
1025
  if (hasScalars()) {
1066
1026
  imports.push("GraphQLScalarType", "GraphQLScalarTypeConfig");
1067
1027
  }
@@ -1162,17 +1122,14 @@ async function loadSchema(schemaPointerMap, cwd) {
1162
1122
  };
1163
1123
  }
1164
1124
 
1165
- // codegen.ts
1125
+ // lib/codegen.ts
1166
1126
  async function generate(options) {
1167
1127
  const root = process.cwd();
1168
1128
  const modulesDir = import_path2.default.relative(root, options.modulesDir || "modules");
1169
1129
  const rootConfig = {
1170
1130
  schemas: (0, import_plugin_helpers4.normalizeInstanceOrArray)(options.schemas),
1171
1131
  modulesDir,
1172
- baseTypesPath: import_path2.default.relative(
1173
- modulesDir,
1174
- options.baseTypesPath || "./__generated__/types.ts"
1175
- ),
1132
+ baseTypesPath: import_path2.default.relative(modulesDir, options.baseTypesPath || "./__generated__/types.ts"),
1176
1133
  contextType: options.contextType,
1177
1134
  moduleDefinitionName: options.moduleDefinitionName || "typedef.ts",
1178
1135
  scalars: options.scalars,
package/index.d.ts CHANGED
@@ -1,14 +1,6 @@
1
- import * as _baeta_plugin from '@baeta/plugin';
1
+ import * as _baeta_config from '@baeta/config';
2
+ import { GraphqlPluginOptions } from '@baeta/config';
2
3
 
3
- interface GraphqlPluginConfig {
4
- schemas: string[];
5
- modulesDir?: string;
6
- moduleDefinitionName?: string;
7
- baseTypesPath?: string;
8
- contextType?: string;
9
- scalars?: Record<string, string>;
10
- }
4
+ declare const _default: (config: GraphqlPluginOptions) => _baeta_config.GeneratorPluginV1WithConfig<GraphqlPluginOptions, {}>;
11
5
 
12
- declare const _default: (config: GraphqlPluginConfig) => _baeta_plugin.GeneratorPluginV1WithConfig<unknown, {}>;
13
-
14
- export { GraphqlPluginConfig, _default as default };
6
+ export { _default as default };
package/index.js CHANGED
@@ -7,13 +7,10 @@ var __export = (target, all) => {
7
7
  // index.ts
8
8
  import { createPluginFactoryV1 } from "@baeta/plugin";
9
9
 
10
- // codegen.ts
10
+ // lib/codegen.ts
11
11
  import { File } from "@baeta/plugin";
12
12
  import { codegen as gqlCodegen } from "@graphql-codegen/core";
13
- import {
14
- normalizeConfig,
15
- normalizeInstanceOrArray
16
- } from "@graphql-codegen/plugin-helpers";
13
+ import { normalizeConfig, normalizeInstanceOrArray } from "@graphql-codegen/plugin-helpers";
17
14
  import * as typescriptPlugin from "@graphql-codegen/typescript";
18
15
  import path from "path";
19
16
 
@@ -160,7 +157,7 @@ function ensureEndsWithSeparator(path2) {
160
157
  return path2.endsWith(sep) ? path2 : path2 + sep;
161
158
  }
162
159
  function ensureStartsWithSeparator(path2) {
163
- return path2.startsWith(".") ? path2.replace(/^(..\/)|(.\/)/, "/") : path2.startsWith("/") ? path2 : "/" + path2;
160
+ return path2.startsWith(".") ? path2.replace(/^(..\/)|(.\/)/, "/") : path2.startsWith("/") ? path2 : `/${path2}`;
164
161
  }
165
162
  function pushUnique(list, item) {
166
163
  if (!list.includes(item)) {
@@ -281,10 +278,11 @@ function buildModule(name, doc, {
281
278
  useTypesPrefix: false,
282
279
  useTypesSuffix: false
283
280
  })} {
284
- ` + (shouldDeclare ? `${indent(2)(imports.join("\n"))}
285
- ` : "") + indent(2)(content) + "\n}";
281
+ ${shouldDeclare ? `${indent(2)(imports.join("\n"))}
282
+ ` : ""}${indent(2)(content)}
283
+ }`;
286
284
  }
287
- return [...!shouldDeclare ? imports : [], content, printFactoryMethod()].filter(Boolean).join("\n");
285
+ return [...shouldDeclare ? [] : imports, content, printFactoryMethod()].filter(Boolean).join("\n");
288
286
  function printMetadata() {
289
287
  return `export namespace ModuleMetadata {
290
288
  export const id = '${name}';
@@ -295,7 +293,7 @@ function buildModule(name, doc, {
295
293
  }
296
294
  function printDefinedFields() {
297
295
  return buildBlock({
298
- name: `interface DefinedFields`,
296
+ name: "interface DefinedFields",
299
297
  lines: [...visited.objects, ...visited.interfaces].map(
300
298
  (typeName) => `${typeName}: ${printPicks(typeName, {
301
299
  ...picks.objects,
@@ -309,17 +307,16 @@ function buildModule(name, doc, {
309
307
  const createModuleFn = `create${name2}Module`;
310
308
  const getModuleFn = `get${name2}Module`;
311
309
  return `
312
- export const ${createModuleFn} = () => Baeta.createModule(ModuleMetadata);
310
+ export const ${createModuleFn} = () => Baeta.createModuleManager(ModuleMetadata);
313
311
  export const ${getModuleFn} = Baeta.createSingletonModule(${createModuleFn});
314
312
  `;
315
313
  }
316
314
  function printObjectFieldResolverBuilder(typeName, field) {
317
315
  const resolverType = `${typeName}Resolvers["${field}"]`;
318
- return `${field}: Baeta.createResolverBuilder<NonNullable<${resolverType}>>("${typeName}", "${field}", options),`;
316
+ return `${field}: Baeta.createResolverBuilder<NonNullable<${resolverType}>>(module, "${typeName}", "${field}"),`;
319
317
  }
320
318
  function printObjectResolverBuilder(typeName, objects) {
321
- var _a;
322
- const fields = ((_a = objects[typeName]) == null ? void 0 : _a.filter(unique).map((field) => printObjectFieldResolverBuilder(typeName, field))) ?? [];
319
+ const fields = objects[typeName]?.filter(unique).map((field) => printObjectFieldResolverBuilder(typeName, field)) ?? [];
323
320
  if (fields.length === 0) {
324
321
  return "";
325
322
  }
@@ -327,26 +324,23 @@ export const ${getModuleFn} = Baeta.createSingletonModule(${createModuleFn});
327
324
  const content2 = `{
328
325
  ${fields.map(indent(2)).join("\n")}
329
326
  }`;
330
- return `${typeName}: Baeta.createResolversBuilder("${typeName}", options, {} as ${resolversType}, ${content2}),`;
327
+ return `${typeName}: Baeta.aggregateResolvers(module, "${typeName}", {} as ${resolversType}, ${content2}),`;
331
328
  }
332
329
  function printSubscriptionFieldBuilder(field) {
333
330
  const resolverType = `SubscriptionResolvers["${field}"]`;
334
- return `${field}: Baeta.createSubscriptionBuilder<${resolverType}>("${field}", options),`;
331
+ return `${field}: Baeta.createSubscriptionBuilder<${resolverType}>(module, "${field}"),`;
335
332
  }
336
333
  function printSubscriptionObjectBuilder() {
337
- var _a;
338
- const subscriptions = ((_a = picks.objects["Subscription"]) == null ? void 0 : _a.filter(unique)) ?? [];
334
+ const subscriptions = picks.objects["Subscription"]?.filter(unique) ?? [];
339
335
  if (subscriptions.length === 0) {
340
336
  return "";
341
337
  }
342
- const fields = subscriptions.map(
343
- (subscription) => printSubscriptionFieldBuilder(subscription)
344
- );
345
- const resolversType = `SubscriptionResolvers`;
338
+ const fields = subscriptions.map((subscription) => printSubscriptionFieldBuilder(subscription));
339
+ const resolversType = "SubscriptionResolvers";
346
340
  const content2 = `{
347
341
  ${fields.map(indent(2)).join("\n")}
348
342
  }`;
349
- return `Subscription: Baeta.createSubscriptionsBuilder(options, {} as ${resolversType}, ${content2}),`;
343
+ return `Subscription: Baeta.aggregateSubscriptions(module, {} as ${resolversType}, ${content2}),`;
350
344
  }
351
345
  function printScalarBuilder() {
352
346
  const scalars = visited.scalars;
@@ -354,7 +348,7 @@ ${fields.map(indent(2)).join("\n")}
354
348
  return "";
355
349
  }
356
350
  const fields = scalars.map(
357
- (scalar) => `${scalar}: Baeta.createScalarBuilder("${scalar}", options),`
351
+ (scalar) => `${scalar}: Baeta.createScalarBuilder(module, "${scalar}"),`
358
352
  );
359
353
  const content2 = fields.map(indent(2)).join("\n");
360
354
  return `Scalar: {
@@ -363,26 +357,20 @@ ${content2}
363
357
  }
364
358
  function printBaetaManager() {
365
359
  const objects = visited.objects.filter((type) => type !== "Subscription").map((typeName) => printObjectResolverBuilder(typeName, picks.objects)).filter(Boolean);
366
- const bodyFields = [
367
- ...objects,
368
- printScalarBuilder(),
369
- printSubscriptionObjectBuilder()
370
- ];
360
+ const bodyFields = [...objects, printScalarBuilder(), printSubscriptionObjectBuilder()];
371
361
  const body = bodyFields.filter(Boolean).map(indent(6)).join("\n");
372
362
  const content2 = `{
373
363
  ${body}
374
364
  }`;
375
365
  return `
376
- export function createManager(options: Baeta.ManagerOptions) {
377
- return Baeta.createManager(options, {}, ${content2});
366
+ export function createManager(module: Baeta.ModuleBuilder) {
367
+ return Baeta.aggregateBuilders(module, {} as Resolvers, ${content2});
378
368
  }`;
379
369
  }
380
370
  function printDefinedEnumValues() {
381
371
  return buildBlock({
382
- name: `interface DefinedEnumValues`,
383
- lines: visited.enums.map(
384
- (typeName) => `${typeName}: ${printPicks(typeName, picks.enums)};`
385
- )
372
+ name: "interface DefinedEnumValues",
373
+ lines: visited.enums.map((typeName) => `${typeName}: ${printPicks(typeName, picks.enums)};`)
386
374
  });
387
375
  }
388
376
  function encapsulateTypeName(typeName) {
@@ -393,7 +381,7 @@ ${body}
393
381
  }
394
382
  function printDefinedInputFields() {
395
383
  return buildBlock({
396
- name: `interface DefinedInputFields`,
384
+ name: "interface DefinedInputFields",
397
385
  lines: visited.inputs.map(
398
386
  (typeName) => `${typeName}: ${printPicks(typeName, picks.inputs)};`
399
387
  )
@@ -435,27 +423,27 @@ ${body}
435
423
  function printResolversType(registry) {
436
424
  const lines = [];
437
425
  for (const kind in registry) {
438
- const k = kind;
439
- if (registry.hasOwnProperty(k) && resolverKeys.includes(k)) {
440
- const types = registry[k];
441
- types.forEach((typeName) => {
442
- if (k === "enums") {
443
- return;
444
- }
445
- if (k === "scalars") {
446
- lines.push(
447
- `${typeName}?: ${encapsulateTypeName(
448
- importNamespace
449
- )}.Resolvers['${typeName}'];`
450
- );
451
- } else {
452
- const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? "" : "?";
453
- lines.push(
454
- `${typeName}${fieldModifier}: ${encapsulateTypeName(typeName)}Resolvers;`
455
- );
456
- }
457
- });
426
+ if (!Object.prototype.hasOwnProperty.call(registry, kind)) {
427
+ continue;
458
428
  }
429
+ if (!resolverKeys.includes(kind)) {
430
+ continue;
431
+ }
432
+ const k = kind;
433
+ const types = registry[k];
434
+ types.forEach((typeName) => {
435
+ if (k === "enums") {
436
+ return;
437
+ }
438
+ if (k === "scalars") {
439
+ lines.push(
440
+ `${typeName}?: ${encapsulateTypeName(importNamespace)}.Resolvers['${typeName}'];`
441
+ );
442
+ } else {
443
+ const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? "" : "?";
444
+ lines.push(`${typeName}${fieldModifier}: ${encapsulateTypeName(typeName)}Resolvers;`);
445
+ }
446
+ });
459
447
  }
460
448
  return buildBlock({
461
449
  name: `export interface ${encapsulateTypeName("Resolvers")}`,
@@ -594,10 +582,7 @@ var preset = {
594
582
  buildGeneratesSection: (options) => {
595
583
  const { baseOutputDir } = options;
596
584
  const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
597
- const requireRootResolvers = getConfigValue(
598
- options == null ? void 0 : options.presetConfig.requireRootResolvers,
599
- false
600
- );
585
+ const requireRootResolvers = getConfigValue(options?.presetConfig.requireRootResolvers, false);
601
586
  const cwd = resolve(options.presetConfig.cwd || process.cwd());
602
587
  const importTypesNamespace = options.presetConfig.importTypesNamespace || "Types";
603
588
  if (!baseTypesPath) {
@@ -605,14 +590,12 @@ var preset = {
605
590
  `Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`
606
591
  );
607
592
  }
608
- if (!options.schemaAst || !options.schemaAst.extensions.sources) {
593
+ if (!options.schemaAst?.extensions.sources) {
609
594
  throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
610
595
  }
611
- const extensions = options.schemaAst.extensions;
612
- const sourcesByModuleMap = groupSourcesByModule(
613
- extensions.extendedSources,
614
- baseOutputDir
615
- );
596
+ const extensions = options.schemaAst?.extensions;
597
+ const sources = extensions?.extendedSources ?? [];
598
+ const sourcesByModuleMap = groupSourcesByModule(sources, baseOutputDir);
616
599
  const modules = Object.keys(sourcesByModuleMap);
617
600
  const baseVisitor = new BaseVisitor(options.config, {});
618
601
  const baseOutput = {
@@ -649,17 +632,12 @@ var preset = {
649
632
  const baseTypesFilename = baseTypesPath.replace(/\.(js|ts|d.ts)$/, "");
650
633
  const baseTypesDir = stripFilename(baseOutput.filename);
651
634
  const outputs = modules.map((moduleName) => {
652
- const filename = resolve(
653
- cwd,
654
- baseOutputDir,
655
- moduleName,
656
- options.presetConfig.filename
657
- );
635
+ const filename = resolve(cwd, baseOutputDir, moduleName, options.presetConfig.filename);
658
636
  const dirpath = stripFilename(filename);
659
637
  const relativePath = relative(dirpath, baseTypesDir);
660
638
  const importPath = options.presetConfig.importBaseTypesFrom || normalize(join(relativePath, baseTypesFilename));
661
- const sources = sourcesByModuleMap[moduleName];
662
- const documents = sources.map((source) => source.document);
639
+ const sources2 = sourcesByModuleMap[moduleName];
640
+ const documents = sources2.map((source) => source.document);
663
641
  const moduleDocument = concatAST(documents);
664
642
  const shouldDeclare = filename.endsWith(".d.ts");
665
643
  return {
@@ -675,24 +653,21 @@ var preset = {
675
653
  pluginMap: {
676
654
  ...options.pluginMap,
677
655
  "graphql-modules-plugin": {
678
- plugin: (schema) => {
679
- var _a, _b, _c;
680
- return buildModule(moduleName, moduleDocument, {
681
- importNamespace: importTypesNamespace,
682
- importPath,
683
- encapsulate: encapsulateModuleTypes || "namespace",
684
- requireRootResolvers,
685
- shouldDeclare,
686
- schema,
687
- baseVisitor,
688
- useGraphQLModules: false,
689
- rootTypes: [
690
- ((_a = schema.getQueryType()) == null ? void 0 : _a.name) || "",
691
- ((_b = schema.getMutationType()) == null ? void 0 : _b.name) || "",
692
- ((_c = schema.getSubscriptionType()) == null ? void 0 : _c.name) || ""
693
- ].filter(Boolean)
694
- });
695
- }
656
+ plugin: (schema) => buildModule(moduleName, moduleDocument, {
657
+ importNamespace: importTypesNamespace,
658
+ importPath,
659
+ encapsulate: encapsulateModuleTypes || "namespace",
660
+ requireRootResolvers,
661
+ shouldDeclare,
662
+ schema,
663
+ baseVisitor,
664
+ useGraphQLModules: false,
665
+ rootTypes: [
666
+ schema.getQueryType()?.name || "",
667
+ schema.getMutationType()?.name || "",
668
+ schema.getSubscriptionType()?.name || ""
669
+ ].filter(Boolean)
670
+ })
696
671
  }
697
672
  },
698
673
  config: options.config,
@@ -731,10 +706,7 @@ var TypeScriptResolversVisitor = class extends BaseResolversVisitor {
731
706
  avoidOptionals: getConfigValue2(pluginConfig.avoidOptionals, false),
732
707
  useIndexSignature: getConfigValue2(pluginConfig.useIndexSignature, false),
733
708
  wrapFieldDefinitions: getConfigValue2(pluginConfig.wrapFieldDefinitions, false),
734
- allowParentTypeOverride: getConfigValue2(
735
- pluginConfig.allowParentTypeOverride,
736
- false
737
- ),
709
+ allowParentTypeOverride: getConfigValue2(pluginConfig.allowParentTypeOverride, false),
738
710
  optionalInfoArgument: getConfigValue2(pluginConfig.optionalInfoArgument, false)
739
711
  },
740
712
  schema
@@ -767,9 +739,10 @@ var TypeScriptResolversVisitor = class extends BaseResolversVisitor {
767
739
  return `ParentType extends ${parentType} = ${parentType}`;
768
740
  }
769
741
  formatRootResolver(schemaTypeName, resolverType, declarationKind) {
770
- var _a;
771
- const avoidOptionals = ((_a = this.config.avoidOptionals) == null ? void 0 : _a.resolvers) ?? this.config.avoidOptionals === true;
772
- return `${schemaTypeName}${avoidOptionals ? "" : "?"}: ${resolverType}${this.getPunctuation(declarationKind)}`;
742
+ const avoidOptionals = this.config.avoidOptionals?.resolvers ?? this.config.avoidOptionals === true;
743
+ return `${schemaTypeName}${avoidOptionals ? "" : "?"}: ${resolverType}${this.getPunctuation(
744
+ declarationKind
745
+ )}`;
773
746
  }
774
747
  clearOptional(str) {
775
748
  if (str.startsWith("Maybe")) {
@@ -800,9 +773,7 @@ var TypeScriptResolversVisitor = class extends BaseResolversVisitor {
800
773
  return ";";
801
774
  }
802
775
  buildEnumResolverContentBlock(node, mappedEnumType) {
803
- const valuesMap = `{ ${(node.values || []).map(
804
- (v) => `${v.name}${this.config.avoidOptionals ? "" : "?"}: any`
805
- ).join(", ")} }`;
776
+ const valuesMap = `{ ${(node.values || []).map((v) => `${v.name}${this.config.avoidOptionals ? "" : "?"}: any`).join(", ")} }`;
806
777
  this._globalDeclarations.add(ENUM_RESOLVERS_SIGNATURE);
807
778
  return `EnumResolverSignature<${valuesMap}, ${mappedEnumType}>`;
808
779
  }
@@ -833,9 +804,7 @@ var plugin = (schema, documents, config) => {
833
804
  const defsToInclude = [];
834
805
  const directiveResolverMappings = {};
835
806
  if (config.directiveResolverMappings) {
836
- for (const [directiveName, mapper] of Object.entries(
837
- config.directiveResolverMappings
838
- )) {
807
+ for (const [directiveName, mapper] of Object.entries(config.directiveResolverMappings)) {
839
808
  const parsedMapper = parseMapper(mapper);
840
809
  const capitalizedDirectiveName = capitalize(directiveName);
841
810
  const resolverFnName = `ResolverFn${capitalizedDirectiveName}`;
@@ -855,9 +824,7 @@ export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TCo
855
824
  `${importType} { ${parsedMapper.import} ${parsedMapper.import !== resolverFnName ? `as ${resolverFnName} ` : ""}} from '${parsedMapper.source}';`
856
825
  );
857
826
  }
858
- prepend.push(
859
- `export${config.useTypeImports ? " type" : ""} { ${resolverFnName} };`
860
- );
827
+ prepend.push(`export${config.useTypeImports ? " type" : ""} { ${resolverFnName} };`);
861
828
  } else {
862
829
  defsToInclude.push(
863
830
  `export type ${resolverFnName}<TResult, TParent, TContext, TArgs> = ${parsedMapper.type}`
@@ -867,9 +834,7 @@ export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TCo
867
834
  defsToInclude.push(`${resolverType2} ${resolverFnUsage2};`);
868
835
  } else {
869
836
  defsToInclude.push(resolverWithResolve2);
870
- defsToInclude.push(
871
- `${resolverType2} ${resolverFnUsage2} | ${resolverWithResolveUsage2};`
872
- );
837
+ defsToInclude.push(`${resolverType2} ${resolverFnUsage2} | ${resolverWithResolveUsage2};`);
873
838
  }
874
839
  directiveResolverMappings[directiveName] = resolverTypeName;
875
840
  }
@@ -893,15 +858,15 @@ export type NewStitchingResolver<TResult, TParent, TContext, TArgs> = {
893
858
  selectionSet: string | ((fieldNode: FieldNode) => SelectionSetNode);
894
859
  resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
895
860
  };`;
896
- const stitchingResolverType = `export type StitchingResolver<TResult, TParent, TContext, TArgs> = LegacyStitchingResolver<TResult, TParent, TContext, TArgs> | NewStitchingResolver<TResult, TParent, TContext, TArgs>;`;
861
+ const stitchingResolverType = "export type StitchingResolver<TResult, TParent, TContext, TArgs> = LegacyStitchingResolver<TResult, TParent, TContext, TArgs> | NewStitchingResolver<TResult, TParent, TContext, TArgs>;";
897
862
  const resolverWithResolve = `
898
863
  export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
899
864
  resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
900
865
  };`;
901
- const resolverType = `export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> =`;
902
- const resolverFnUsage = `ResolverFn<TResult, TParent, TContext, TArgs>`;
903
- const resolverWithResolveUsage = `ResolverWithResolve<TResult, TParent, TContext, TArgs>`;
904
- const stitchingResolverUsage = `StitchingResolver<TResult, TParent, TContext, TArgs>`;
866
+ const resolverType = "export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> =";
867
+ const resolverFnUsage = "ResolverFn<TResult, TParent, TContext, TArgs>";
868
+ const resolverWithResolveUsage = "ResolverWithResolve<TResult, TParent, TContext, TArgs>";
869
+ const stitchingResolverUsage = "StitchingResolver<TResult, TParent, TContext, TArgs>";
905
870
  if (visitor.hasFederation()) {
906
871
  if (visitor.config.wrapFieldDefinitions) {
907
872
  defsToInclude.push(`export type UnwrappedObject<T> = {
@@ -935,7 +900,7 @@ export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
935
900
  stitchingResolverType,
936
901
  resolverType,
937
902
  ` | ${resolverFnUsage}`,
938
- config.makeResolverTypeCallable ? `` : ` | ${resolverWithResolveUsage}`,
903
+ config.makeResolverTypeCallable ? "" : ` | ${resolverWithResolveUsage}`,
939
904
  ` | ${stitchingResolverUsage};`
940
905
  ].join("\n")
941
906
  );
@@ -977,9 +942,7 @@ export type ResolverFn<TResult, TParent, TContext, TArgs> = (
977
942
  `${importType} { ${parsedMapper.import} ${parsedMapper.import !== "SubscriptionResolver" ? "as SubscriptionResolver " : ""}} from '${parsedMapper.source}';`
978
943
  );
979
944
  }
980
- prepend.push(
981
- `export${config.useTypeImports ? " type" : ""} { SubscriptionResolver };`
982
- );
945
+ prepend.push(`export${config.useTypeImports ? " type" : ""} { SubscriptionResolver };`);
983
946
  } else {
984
947
  prepend.push(
985
948
  `export type SubscriptionResolver<TResult, TKey extends string, TParent = {}, TContext = {}, TArgs = {}> = ${parsedMapper.type}`
@@ -1047,13 +1010,7 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
1047
1010
  `;
1048
1011
  const resolversTypeMapping = visitor.buildResolversTypes();
1049
1012
  const resolversParentTypeMapping = visitor.buildResolversParentTypes();
1050
- const {
1051
- getRootResolver,
1052
- getAllDirectiveResolvers,
1053
- mappersImports,
1054
- unusedMappers,
1055
- hasScalars
1056
- } = visitor;
1013
+ const { getRootResolver, getAllDirectiveResolvers, mappersImports, unusedMappers, hasScalars } = visitor;
1057
1014
  if (hasScalars()) {
1058
1015
  imports.push("GraphQLScalarType", "GraphQLScalarTypeConfig");
1059
1016
  }
@@ -1113,16 +1070,14 @@ import { GitLoader } from "@graphql-tools/git-loader";
1113
1070
  import { GithubLoader } from "@graphql-tools/github-loader";
1114
1071
  import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
1115
1072
  import { JsonFileLoader } from "@graphql-tools/json-file-loader";
1116
- import {
1117
- loadSchema as loadSchemaToolkit
1118
- } from "@graphql-tools/load";
1073
+ import { loadSchema as loadSchemaToolkit } from "@graphql-tools/load";
1119
1074
  import { PrismaLoader } from "@graphql-tools/prisma-loader";
1120
1075
  import { UrlLoader } from "@graphql-tools/url-loader";
1121
1076
 
1122
1077
  // utils/hash.ts
1123
1078
  import { getCachedDocumentNodeFromSchema as getCachedDocumentNodeFromSchema2 } from "@graphql-codegen/plugin-helpers";
1124
1079
  import { print } from "graphql";
1125
- import { createHash } from "node:crypto";
1080
+ import { createHash } from "crypto";
1126
1081
  function hashContent(content) {
1127
1082
  return createHash("sha256").update(content).digest("hex");
1128
1083
  }
@@ -1156,17 +1111,14 @@ async function loadSchema(schemaPointerMap, cwd) {
1156
1111
  };
1157
1112
  }
1158
1113
 
1159
- // codegen.ts
1114
+ // lib/codegen.ts
1160
1115
  async function generate(options) {
1161
1116
  const root = process.cwd();
1162
1117
  const modulesDir = path.relative(root, options.modulesDir || "modules");
1163
1118
  const rootConfig = {
1164
1119
  schemas: normalizeInstanceOrArray(options.schemas),
1165
1120
  modulesDir,
1166
- baseTypesPath: path.relative(
1167
- modulesDir,
1168
- options.baseTypesPath || "./__generated__/types.ts"
1169
- ),
1121
+ baseTypesPath: path.relative(modulesDir, options.baseTypesPath || "./__generated__/types.ts"),
1170
1122
  contextType: options.contextType,
1171
1123
  moduleDefinitionName: options.moduleDefinitionName || "typedef.ts",
1172
1124
  scalars: options.scalars,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/plugin-graphql",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "author": "Andrei Pampu <pampu.andrei@pm.me>",
6
6
  "homepage": "https://github.com/andreisergiu98/baeta#readme",
@@ -13,61 +13,57 @@
13
13
  "url": "https://github.com/andreisergiu98/baeta/issues"
14
14
  },
15
15
  "type": "module",
16
- "scripts": {
17
- "prepack": "yarn prep --move dist",
18
- "postpack": "yarn prep --clean",
19
- "build": "yarn tsup --dts",
20
- "lint": "yarn eslint './**/*.ts'"
21
- },
22
16
  "dependencies": {
23
- "@baeta/plugin": "workspace:^",
24
- "@graphql-codegen/core": "^2.6.2",
25
- "@graphql-codegen/plugin-helpers": "^2.7.1",
26
- "@graphql-codegen/typescript": "^2.7.3",
27
- "@graphql-codegen/typescript-resolvers": "^2.7.3",
28
- "@graphql-codegen/visitor-plugin-common": "2.12.1",
29
- "@graphql-tools/apollo-engine-loader": "^7.3.13",
30
- "@graphql-tools/code-file-loader": "^7.3.6",
31
- "@graphql-tools/git-loader": "^7.2.6",
32
- "@graphql-tools/github-loader": "^7.3.13",
33
- "@graphql-tools/graphql-file-loader": "^7.5.5",
34
- "@graphql-tools/json-file-loader": "^7.4.6",
35
- "@graphql-tools/load": "^7.7.7",
36
- "@graphql-tools/prisma-loader": "^7.2.22",
37
- "@graphql-tools/url-loader": "^7.16.2",
38
- "@graphql-tools/utils": "^8.12.0",
17
+ "@graphql-codegen/core": "^2.6.6",
18
+ "@graphql-codegen/plugin-helpers": "^2.7.2",
19
+ "@graphql-codegen/typescript": "^2.8.2",
20
+ "@graphql-codegen/typescript-resolvers": "^2.7.7",
21
+ "@graphql-codegen/visitor-plugin-common": "2.13.2",
22
+ "@graphql-tools/apollo-engine-loader": "^7.3.19",
23
+ "@graphql-tools/code-file-loader": "^7.3.13",
24
+ "@graphql-tools/git-loader": "^7.2.13",
25
+ "@graphql-tools/github-loader": "^7.3.20",
26
+ "@graphql-tools/graphql-file-loader": "^7.5.11",
27
+ "@graphql-tools/json-file-loader": "^7.4.12",
28
+ "@graphql-tools/load": "^7.8.6",
29
+ "@graphql-tools/prisma-loader": "^7.2.40",
30
+ "@graphql-tools/url-loader": "^7.16.20",
31
+ "@graphql-tools/utils": "^9.1.1",
39
32
  "auto-bind": "^5.0.1",
40
33
  "change-case-all": "1.0.15",
41
34
  "parse-filepath": "^1.0.2",
42
- "tslib": "^2.4.0"
35
+ "tslib": "^2.4.1",
36
+ "@baeta/config": "^0.0.2",
37
+ "@baeta/plugin": "^0.0.7"
43
38
  },
44
39
  "devDependencies": {
45
- "@baeta/eslint-config": "workspace:^",
46
- "@baeta/prep": "workspace:^",
47
- "@types/node": "^18.7.23",
40
+ "@types/node": "^18.11.9",
48
41
  "@types/parse-filepath": "1.0.0",
49
- "eslint": "^8.24.0",
50
42
  "graphql": "^16.6.0",
51
- "typescript": "^4.8.3"
43
+ "tsup": "^6.5.0",
44
+ "typescript": "^4.9.3"
52
45
  },
53
46
  "peerDependencies": {
54
- "@baeta/core": "workspace:^",
55
47
  "graphql": "^15.3.0 || ^16.0.0"
56
48
  },
57
49
  "files": [
58
50
  "*.js",
59
51
  "*.cjs",
60
- "*.d.ts",
61
- "!.eslintrc.cjs"
52
+ "*.d.ts"
62
53
  ],
63
54
  "publishConfig": {
64
55
  "access": "public",
65
- "exports": {
66
- ".": {
67
- "import": "./index.js",
68
- "require": "./index.cjs",
69
- "types": "./index.d.ts"
70
- }
56
+ "directory": "dist"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "types": "tsc --noEmit"
61
+ },
62
+ "exports": {
63
+ ".": {
64
+ "import": "./index.js",
65
+ "require": "./index.cjs",
66
+ "types": "./index.d.ts"
71
67
  }
72
68
  }
73
- }
69
+ }