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

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,11 +38,14 @@ 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
43
  // Collect all type names referenced in the document
42
44
  const referencedTypeNames = new Set();
43
45
  (0, graphql_1.visit)(document, {
44
46
  // Check variable types for input types or custom scalars
45
47
  VariableDefinition: (node) => {
48
+ hasVariables = true; // Any variable means we need Types import
46
49
  const typeName = getBaseTypeName(node.type);
47
50
  referencedTypeNames.add(typeName);
48
51
  },
@@ -51,6 +54,10 @@ function needsSchemaTypesImport(document, schema, config) {
51
54
  referencedTypeNames.add(node.typeCondition.name.value);
52
55
  },
53
56
  });
57
+ // If operation has variables, it will use Types.Exact, Types.Scalars, Types.InputMaybe, etc.
58
+ if (hasVariables) {
59
+ return true;
60
+ }
54
61
  // Helper to recursively check if a type needs importing
55
62
  const checkType = (type) => {
56
63
  if (!type)
package/esm/index.js CHANGED
@@ -34,11 +34,14 @@ 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
39
  // Collect all type names referenced in the document
38
40
  const referencedTypeNames = new Set();
39
41
  visit(document, {
40
42
  // Check variable types for input types or custom scalars
41
43
  VariableDefinition: (node) => {
44
+ hasVariables = true; // Any variable means we need Types import
42
45
  const typeName = getBaseTypeName(node.type);
43
46
  referencedTypeNames.add(typeName);
44
47
  },
@@ -47,6 +50,10 @@ function needsSchemaTypesImport(document, schema, config) {
47
50
  referencedTypeNames.add(node.typeCondition.name.value);
48
51
  },
49
52
  });
53
+ // If operation has variables, it will use Types.Exact, Types.Scalars, Types.InputMaybe, etc.
54
+ if (hasVariables) {
55
+ return true;
56
+ }
50
57
  // Helper to recursively check if a type needs importing
51
58
  const checkType = (type) => {
52
59
  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.4",
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"