@nmarks/graphql-codegen-per-operation-file-preset 1.0.3 → 1.0.5

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/cjs/index.js CHANGED
@@ -38,9 +38,17 @@ function needsSchemaTypesImport(document, schema, config) {
38
38
  let needsImport = false;
39
39
  // Get scalar mappings from config
40
40
  const scalarMappings = config.scalars || {};
41
+ // Check if document has an operation definition
42
+ // ALL operations (query/mutation/subscription) generate a Variables type that uses Types.Exact
43
+ // even if they have no variables: Types.Exact<{ [key: string]: never; }>
44
+ let hasOperation = false;
41
45
  // Collect all type names referenced in the document
42
46
  const referencedTypeNames = new Set();
43
47
  (0, graphql_1.visit)(document, {
48
+ // Operations always need Types import for their Variables type
49
+ OperationDefinition: () => {
50
+ hasOperation = true;
51
+ },
44
52
  // Check variable types for input types or custom scalars
45
53
  VariableDefinition: (node) => {
46
54
  const typeName = getBaseTypeName(node.type);
@@ -51,6 +59,10 @@ function needsSchemaTypesImport(document, schema, config) {
51
59
  referencedTypeNames.add(node.typeCondition.name.value);
52
60
  },
53
61
  });
62
+ // All operations generate Variables type that uses Types.Exact
63
+ if (hasOperation) {
64
+ return true;
65
+ }
54
66
  // Helper to recursively check if a type needs importing
55
67
  const checkType = (type) => {
56
68
  if (!type)
package/esm/index.js CHANGED
@@ -34,9 +34,17 @@ function needsSchemaTypesImport(document, schema, config) {
34
34
  let needsImport = false;
35
35
  // Get scalar mappings from config
36
36
  const scalarMappings = config.scalars || {};
37
+ // Check if document has an operation definition
38
+ // ALL operations (query/mutation/subscription) generate a Variables type that uses Types.Exact
39
+ // even if they have no variables: Types.Exact<{ [key: string]: never; }>
40
+ let hasOperation = false;
37
41
  // Collect all type names referenced in the document
38
42
  const referencedTypeNames = new Set();
39
43
  visit(document, {
44
+ // Operations always need Types import for their Variables type
45
+ OperationDefinition: () => {
46
+ hasOperation = true;
47
+ },
40
48
  // Check variable types for input types or custom scalars
41
49
  VariableDefinition: (node) => {
42
50
  const typeName = getBaseTypeName(node.type);
@@ -47,6 +55,10 @@ function needsSchemaTypesImport(document, schema, config) {
47
55
  referencedTypeNames.add(node.typeCondition.name.value);
48
56
  },
49
57
  });
58
+ // All operations generate Variables type that uses Types.Exact
59
+ if (hasOperation) {
60
+ return true;
61
+ }
50
62
  // Helper to recursively check if a type needs importing
51
63
  const checkType = (type) => {
52
64
  if (!type)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmarks/graphql-codegen-per-operation-file-preset",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "GraphQL Code Generator preset for generating one file per operation/fragment",
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"