@graphql-codegen/gql-tag-operations 4.0.13 → 4.0.14-alpha-20250131154420-ffe0538fd3eb19302ae3bee1ffab28a5710a04b9

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 (3) hide show
  1. package/cjs/index.js +20 -10
  2. package/esm/index.js +20 -10
  3. package/package.json +1 -1
package/cjs/index.js CHANGED
@@ -83,20 +83,30 @@ const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleN
83
83
  };
84
84
  exports.plugin = plugin;
85
85
  function getDocumentRegistryChunk(sourcesWithOperations = []) {
86
- const lines = new Set();
87
- lines.add(`/**\n * Map of all GraphQL operations in the project.\n *\n * This map has several performance disadvantages:\n`);
88
- lines.add(` * 1. It is not tree-shakeable, so it will include all operations in the project.\n`);
89
- lines.add(` * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.\n`);
90
- lines.add(` * 3. It does not support dead code elimination, so it will add unused operations.\n *\n`);
91
- lines.add(` * Therefore it is highly recommended to use the babel or swc plugin for production.\n`);
92
- lines.add(` * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size\n */\n`);
93
- lines.add(`const documents = {\n`);
86
+ const lines = new Array();
87
+ // It's possible for there to be duplicate sourceOperations, this set will ensure we have unique records for our document registry
88
+ const linesDupCheck = new Set();
89
+ lines.push(`/**\n * Map of all GraphQL operations in the project.\n *\n * This map has several performance disadvantages:\n`, ` * 1. It is not tree-shakeable, so it will include all operations in the project.\n`, ` * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.\n`, ` * 3. It does not support dead code elimination, so it will add unused operations.\n *\n`, ` * Therefore it is highly recommended to use the babel or swc plugin for production.\n`, ` * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size\n */\n`, `type Documents = {\n`);
94
90
  for (const { operations, ...rest } of sourcesWithOperations) {
95
91
  const originalString = rest.source.rawSDL;
96
92
  const operation = operations[0];
97
- lines.add(` ${JSON.stringify(originalString)}: types.${operation.initialName},\n`);
93
+ const aboutToPushLine = ` ${JSON.stringify(originalString)}: typeof types.${operation.initialName},\n`;
94
+ if (!linesDupCheck.has(aboutToPushLine)) {
95
+ lines.push(aboutToPushLine);
96
+ linesDupCheck.add(aboutToPushLine);
97
+ }
98
+ }
99
+ lines.push(`};\n`, `const documents: Documents = {\n`);
100
+ for (const { operations, ...rest } of sourcesWithOperations) {
101
+ const originalString = rest.source.rawSDL;
102
+ const operation = operations[0];
103
+ const aboutToPushLine = ` ${JSON.stringify(originalString)}: types.${operation.initialName},\n`;
104
+ if (!linesDupCheck.has(aboutToPushLine)) {
105
+ lines.push(aboutToPushLine);
106
+ linesDupCheck.add(aboutToPushLine);
107
+ }
98
108
  }
99
- lines.add(`};\n`);
109
+ lines.push(`};\n`);
100
110
  return lines;
101
111
  }
102
112
  function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, emitLegacyCommonJSImports) {
package/esm/index.js CHANGED
@@ -79,20 +79,30 @@ export const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmented
79
79
  ].join(`\n`);
80
80
  };
81
81
  function getDocumentRegistryChunk(sourcesWithOperations = []) {
82
- const lines = new Set();
83
- lines.add(`/**\n * Map of all GraphQL operations in the project.\n *\n * This map has several performance disadvantages:\n`);
84
- lines.add(` * 1. It is not tree-shakeable, so it will include all operations in the project.\n`);
85
- lines.add(` * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.\n`);
86
- lines.add(` * 3. It does not support dead code elimination, so it will add unused operations.\n *\n`);
87
- lines.add(` * Therefore it is highly recommended to use the babel or swc plugin for production.\n`);
88
- lines.add(` * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size\n */\n`);
89
- lines.add(`const documents = {\n`);
82
+ const lines = new Array();
83
+ // It's possible for there to be duplicate sourceOperations, this set will ensure we have unique records for our document registry
84
+ const linesDupCheck = new Set();
85
+ lines.push(`/**\n * Map of all GraphQL operations in the project.\n *\n * This map has several performance disadvantages:\n`, ` * 1. It is not tree-shakeable, so it will include all operations in the project.\n`, ` * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.\n`, ` * 3. It does not support dead code elimination, so it will add unused operations.\n *\n`, ` * Therefore it is highly recommended to use the babel or swc plugin for production.\n`, ` * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size\n */\n`, `type Documents = {\n`);
90
86
  for (const { operations, ...rest } of sourcesWithOperations) {
91
87
  const originalString = rest.source.rawSDL;
92
88
  const operation = operations[0];
93
- lines.add(` ${JSON.stringify(originalString)}: types.${operation.initialName},\n`);
89
+ const aboutToPushLine = ` ${JSON.stringify(originalString)}: typeof types.${operation.initialName},\n`;
90
+ if (!linesDupCheck.has(aboutToPushLine)) {
91
+ lines.push(aboutToPushLine);
92
+ linesDupCheck.add(aboutToPushLine);
93
+ }
94
+ }
95
+ lines.push(`};\n`, `const documents: Documents = {\n`);
96
+ for (const { operations, ...rest } of sourcesWithOperations) {
97
+ const originalString = rest.source.rawSDL;
98
+ const operation = operations[0];
99
+ const aboutToPushLine = ` ${JSON.stringify(originalString)}: types.${operation.initialName},\n`;
100
+ if (!linesDupCheck.has(aboutToPushLine)) {
101
+ lines.push(aboutToPushLine);
102
+ linesDupCheck.add(aboutToPushLine);
103
+ }
94
104
  }
95
- lines.add(`};\n`);
105
+ lines.push(`};\n`);
96
106
  return lines;
97
107
  }
98
108
  function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, emitLegacyCommonJSImports) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/gql-tag-operations",
3
- "version": "4.0.13",
3
+ "version": "4.0.14-alpha-20250131154420-ffe0538fd3eb19302ae3bee1ffab28a5710a04b9",
4
4
  "description": "GraphQL Code Generator plugin for generating a typed gql tag function",
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"