@nmarks/graphql-codegen-per-operation-file-preset 1.0.4 → 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,14 +38,19 @@ 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 any variables - if so, we need Types import for Types.Exact, Types.Scalars, etc.
42
- let hasVariables = false;
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;
43
45
  // Collect all type names referenced in the document
44
46
  const referencedTypeNames = new Set();
45
47
  (0, graphql_1.visit)(document, {
48
+ // Operations always need Types import for their Variables type
49
+ OperationDefinition: () => {
50
+ hasOperation = true;
51
+ },
46
52
  // Check variable types for input types or custom scalars
47
53
  VariableDefinition: (node) => {
48
- hasVariables = true; // Any variable means we need Types import
49
54
  const typeName = getBaseTypeName(node.type);
50
55
  referencedTypeNames.add(typeName);
51
56
  },
@@ -54,8 +59,8 @@ function needsSchemaTypesImport(document, schema, config) {
54
59
  referencedTypeNames.add(node.typeCondition.name.value);
55
60
  },
56
61
  });
57
- // If operation has variables, it will use Types.Exact, Types.Scalars, Types.InputMaybe, etc.
58
- if (hasVariables) {
62
+ // All operations generate Variables type that uses Types.Exact
63
+ if (hasOperation) {
59
64
  return true;
60
65
  }
61
66
  // Helper to recursively check if a type needs importing
package/esm/index.js CHANGED
@@ -34,14 +34,19 @@ 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 any variables - if so, we need Types import for Types.Exact, Types.Scalars, etc.
38
- let hasVariables = false;
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;
39
41
  // Collect all type names referenced in the document
40
42
  const referencedTypeNames = new Set();
41
43
  visit(document, {
44
+ // Operations always need Types import for their Variables type
45
+ OperationDefinition: () => {
46
+ hasOperation = true;
47
+ },
42
48
  // Check variable types for input types or custom scalars
43
49
  VariableDefinition: (node) => {
44
- hasVariables = true; // Any variable means we need Types import
45
50
  const typeName = getBaseTypeName(node.type);
46
51
  referencedTypeNames.add(typeName);
47
52
  },
@@ -50,8 +55,8 @@ function needsSchemaTypesImport(document, schema, config) {
50
55
  referencedTypeNames.add(node.typeCondition.name.value);
51
56
  },
52
57
  });
53
- // If operation has variables, it will use Types.Exact, Types.Scalars, Types.InputMaybe, etc.
54
- if (hasVariables) {
58
+ // All operations generate Variables type that uses Types.Exact
59
+ if (hasOperation) {
55
60
  return true;
56
61
  }
57
62
  // Helper to recursively check if a type needs importing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmarks/graphql-codegen-per-operation-file-preset",
3
- "version": "1.0.4",
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"