@graphql-codegen/typescript-operations 4.5.2-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a → 4.6.0-alpha-20250321113444-b7d75d557b0d9391b452925992a9dabce7d51942

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
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.TypeScriptDocumentsVisitor = exports.plugin = void 0;
4
27
  const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
@@ -6,9 +29,10 @@ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common"
6
29
  const graphql_1 = require("graphql");
7
30
  const visitor_js_1 = require("./visitor.js");
8
31
  Object.defineProperty(exports, "TypeScriptDocumentsVisitor", { enumerable: true, get: function () { return visitor_js_1.TypeScriptDocumentsVisitor; } });
9
- const plugin = (schema, rawDocuments, config) => {
32
+ const plugin = async (schema, rawDocuments, config) => {
33
+ const transformedSchema = config.semanticNonNull?.errorHandlingClient ? await semanticToStrict(schema) : schema;
10
34
  const documents = config.flattenGeneratedTypes
11
- ? (0, visitor_plugin_common_1.optimizeOperations)(schema, rawDocuments, {
35
+ ? (0, visitor_plugin_common_1.optimizeOperations)(transformedSchema, rawDocuments, {
12
36
  includeFragments: config.flattenGeneratedTypesIncludeFragments,
13
37
  })
14
38
  : rawDocuments;
@@ -22,7 +46,7 @@ const plugin = (schema, rawDocuments, config) => {
22
46
  })),
23
47
  ...(config.externalFragments || []),
24
48
  ];
25
- const visitor = new visitor_js_1.TypeScriptDocumentsVisitor(schema, config, allFragments);
49
+ const visitor = new visitor_js_1.TypeScriptDocumentsVisitor(transformedSchema, config, allFragments);
26
50
  const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, {
27
51
  leave: visitor,
28
52
  });
@@ -48,3 +72,12 @@ const plugin = (schema, rawDocuments, config) => {
48
72
  };
49
73
  };
50
74
  exports.plugin = plugin;
75
+ const semanticToStrict = async (schema) => {
76
+ try {
77
+ const sock = await Promise.resolve().then(() => __importStar(require('graphql-sock')));
78
+ return sock.semanticToStrict(schema);
79
+ }
80
+ catch {
81
+ throw new Error("To use the `customDirective.semanticNonNull` option, you must install the 'graphql-sock' package.");
82
+ }
83
+ };
package/esm/index.js CHANGED
@@ -2,9 +2,10 @@ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
2
  import { optimizeOperations } from '@graphql-codegen/visitor-plugin-common';
3
3
  import { concatAST, Kind } from 'graphql';
4
4
  import { TypeScriptDocumentsVisitor } from './visitor.js';
5
- export const plugin = (schema, rawDocuments, config) => {
5
+ export const plugin = async (schema, rawDocuments, config) => {
6
+ const transformedSchema = config.semanticNonNull?.errorHandlingClient ? await semanticToStrict(schema) : schema;
6
7
  const documents = config.flattenGeneratedTypes
7
- ? optimizeOperations(schema, rawDocuments, {
8
+ ? optimizeOperations(transformedSchema, rawDocuments, {
8
9
  includeFragments: config.flattenGeneratedTypesIncludeFragments,
9
10
  })
10
11
  : rawDocuments;
@@ -18,7 +19,7 @@ export const plugin = (schema, rawDocuments, config) => {
18
19
  })),
19
20
  ...(config.externalFragments || []),
20
21
  ];
21
- const visitor = new TypeScriptDocumentsVisitor(schema, config, allFragments);
22
+ const visitor = new TypeScriptDocumentsVisitor(transformedSchema, config, allFragments);
22
23
  const visitorResult = oldVisit(allAst, {
23
24
  leave: visitor,
24
25
  });
@@ -44,3 +45,12 @@ export const plugin = (schema, rawDocuments, config) => {
44
45
  };
45
46
  };
46
47
  export { TypeScriptDocumentsVisitor };
48
+ const semanticToStrict = async (schema) => {
49
+ try {
50
+ const sock = await import('graphql-sock');
51
+ return sock.semanticToStrict(schema);
52
+ }
53
+ catch {
54
+ throw new Error("To use the `customDirective.semanticNonNull` option, you must install the 'graphql-sock' package.");
55
+ }
56
+ };
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-operations",
3
- "version": "4.5.2-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a",
3
+ "version": "4.6.0-alpha-20250321113444-b7d75d557b0d9391b452925992a9dabce7d51942",
4
4
  "description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments",
5
5
  "peerDependencies": {
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"
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",
7
+ "graphql-sock": "^1.0.0"
7
8
  },
8
9
  "dependencies": {
9
- "@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a",
10
- "@graphql-codegen/typescript": "4.1.6-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a",
11
- "@graphql-codegen/visitor-plugin-common": "6.0.0-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a",
10
+ "@graphql-codegen/plugin-helpers": "^5.1.0",
11
+ "@graphql-codegen/typescript": "4.1.6-alpha-20250321113444-b7d75d557b0d9391b452925992a9dabce7d51942",
12
+ "@graphql-codegen/visitor-plugin-common": "5.8.0-alpha-20250321113444-b7d75d557b0d9391b452925992a9dabce7d51942",
12
13
  "auto-bind": "~4.0.0",
13
14
  "tslib": "~2.6.0"
14
15
  },
@@ -287,4 +287,41 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
287
287
  * ```
288
288
  */
289
289
  allowUndefinedQueryVariables?: boolean;
290
+ /**
291
+ * @description Options related to `@semanticNonNull` directive
292
+ * @exampleMarkdown
293
+ * ## `errorHandlingClient`
294
+ * When using error handling clients, a semantic non-nullable field can never be `null`.
295
+ * If a field is read and its value is `null`, there must be a respective error. The error handling client will throw in this case, so the `null` value is never read.
296
+ *
297
+ * To enable this option, install `graphql-sock` peer dependency:
298
+ *
299
+ * ```sh npm2yarn
300
+ * npm install -D graphql-sock
301
+ * ```
302
+ *
303
+ * Now, you can enable support for error handling clients:
304
+ *
305
+ * ```ts filename="codegen.ts"
306
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
307
+ *
308
+ * const config: CodegenConfig = {
309
+ * // ...
310
+ * generates: {
311
+ * 'path/to/file.ts': {
312
+ * plugins: ['typescript', 'typescript-operations'],
313
+ * config: {
314
+ * semanticNonNull: {
315
+ * errorHandlingClient: true
316
+ * }
317
+ * },
318
+ * },
319
+ * },
320
+ * };
321
+ * export default config;
322
+ * ```
323
+ */
324
+ semanticNonNull?: {
325
+ errorHandlingClient: boolean;
326
+ };
290
327
  }
@@ -287,4 +287,41 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
287
287
  * ```
288
288
  */
289
289
  allowUndefinedQueryVariables?: boolean;
290
+ /**
291
+ * @description Options related to `@semanticNonNull` directive
292
+ * @exampleMarkdown
293
+ * ## `errorHandlingClient`
294
+ * When using error handling clients, a semantic non-nullable field can never be `null`.
295
+ * If a field is read and its value is `null`, there must be a respective error. The error handling client will throw in this case, so the `null` value is never read.
296
+ *
297
+ * To enable this option, install `graphql-sock` peer dependency:
298
+ *
299
+ * ```sh npm2yarn
300
+ * npm install -D graphql-sock
301
+ * ```
302
+ *
303
+ * Now, you can enable support for error handling clients:
304
+ *
305
+ * ```ts filename="codegen.ts"
306
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
307
+ *
308
+ * const config: CodegenConfig = {
309
+ * // ...
310
+ * generates: {
311
+ * 'path/to/file.ts': {
312
+ * plugins: ['typescript', 'typescript-operations'],
313
+ * config: {
314
+ * semanticNonNull: {
315
+ * errorHandlingClient: true
316
+ * }
317
+ * },
318
+ * },
319
+ * },
320
+ * };
321
+ * export default config;
322
+ * ```
323
+ */
324
+ semanticNonNull?: {
325
+ errorHandlingClient: boolean;
326
+ };
290
327
  }