@graphql-codegen/client-preset 5.0.0-alpha-20241122105532-fb4c4a5ddeaf1cff18b2974d76989c20c66aea2d → 5.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043
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 +20 -7
- package/cjs/persisted-documents.js +14 -2
- package/esm/index.js +20 -7
- package/esm/persisted-documents.js +14 -2
- package/package.json +15 -9
- package/typings/index.d.cts +3 -3
- package/typings/index.d.ts +3 -3
package/cjs/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const typedDocumentNodePlugin = tslib_1.__importStar(require("@graphql-codegen/t
|
|
|
8
8
|
const typescriptPlugin = tslib_1.__importStar(require("@graphql-codegen/typescript"));
|
|
9
9
|
const typescriptOperationPlugin = tslib_1.__importStar(require("@graphql-codegen/typescript-operations"));
|
|
10
10
|
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
11
|
+
const graphql_1 = require("graphql");
|
|
11
12
|
const fragmentMaskingPlugin = tslib_1.__importStar(require("./fragment-masking-plugin.js"));
|
|
12
13
|
const persisted_documents_js_1 = require("./persisted-documents.js");
|
|
13
14
|
const process_sources_js_1 = require("./process-sources.js");
|
|
@@ -16,7 +17,7 @@ Object.defineProperty(exports, "babelOptimizerPlugin", { enumerable: true, get:
|
|
|
16
17
|
const isOutputFolderLike = (baseOutputDir) => baseOutputDir.endsWith('/');
|
|
17
18
|
exports.preset = {
|
|
18
19
|
prepareDocuments: (outputFilePath, outputSpecificDocuments) => [...outputSpecificDocuments, `!${outputFilePath}`],
|
|
19
|
-
buildGeneratesSection: options => {
|
|
20
|
+
buildGeneratesSection: async (options) => {
|
|
20
21
|
if (!isOutputFolderLike(options.baseOutputDir)) {
|
|
21
22
|
throw new Error('[client-preset] target output should be a directory, ex: "src/gql/". Make sure you add "/" at the end of the directory path');
|
|
22
23
|
}
|
|
@@ -24,6 +25,10 @@ exports.preset = {
|
|
|
24
25
|
throw new Error('[client-preset] providing typescript-based `plugins` with `preset: "client" leads to duplicated generated types');
|
|
25
26
|
}
|
|
26
27
|
const isPersistedOperations = !!options.presetConfig?.persistedDocuments;
|
|
28
|
+
if (options.config.nullability?.errorHandlingClient) {
|
|
29
|
+
options.schemaAst = await semanticToStrict(options.schemaAst);
|
|
30
|
+
options.schema = (0, graphql_1.parse)((0, graphql_1.printSchema)(options.schemaAst));
|
|
31
|
+
}
|
|
27
32
|
const reexports = [];
|
|
28
33
|
// the `client` preset is restricting the config options inherited from `typescript`, `typescript-operations` and others.
|
|
29
34
|
const forwardedConfig = {
|
|
@@ -36,12 +41,16 @@ exports.preset = {
|
|
|
36
41
|
arrayInputCoercion: options.config.arrayInputCoercion,
|
|
37
42
|
enumsAsTypes: options.config.enumsAsTypes,
|
|
38
43
|
enumsAsConst: options.config.enumsAsConst,
|
|
44
|
+
enumValues: options.config.enumValues,
|
|
39
45
|
futureProofEnums: options.config.futureProofEnums,
|
|
40
46
|
dedupeFragments: options.config.dedupeFragments,
|
|
41
47
|
nonOptionalTypename: options.config.nonOptionalTypename,
|
|
42
48
|
avoidOptionals: options.config.avoidOptionals,
|
|
43
49
|
documentMode: options.config.documentMode,
|
|
44
50
|
skipTypeNameForRoot: options.config.skipTypeNameForRoot,
|
|
51
|
+
onlyOperationTypes: options.config.onlyOperationTypes,
|
|
52
|
+
onlyEnums: options.config.onlyEnums,
|
|
53
|
+
customDirectives: options.config.customDirectives,
|
|
45
54
|
};
|
|
46
55
|
const visitor = new visitor_plugin_common_1.ClientSideBaseVisitor(options.schemaAst, [], options.config, options.config);
|
|
47
56
|
let fragmentMaskingConfig = null;
|
|
@@ -108,12 +117,7 @@ exports.preset = {
|
|
|
108
117
|
}
|
|
109
118
|
const plugins = [
|
|
110
119
|
{ [`add`]: { content: `/* eslint-disable */` } },
|
|
111
|
-
{
|
|
112
|
-
[`typescript`]: {
|
|
113
|
-
onlyEnumTypes: true,
|
|
114
|
-
onlyOperationTypes: true,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
120
|
+
{ [`typescript`]: {} },
|
|
117
121
|
{ [`typescript-operations`]: {} },
|
|
118
122
|
{
|
|
119
123
|
[`typed-document-node`]: {
|
|
@@ -248,5 +252,14 @@ function createDeferred() {
|
|
|
248
252
|
});
|
|
249
253
|
return d;
|
|
250
254
|
}
|
|
255
|
+
const semanticToStrict = async (schema) => {
|
|
256
|
+
try {
|
|
257
|
+
const sock = await Promise.resolve().then(() => tslib_1.__importStar(require('graphql-sock')));
|
|
258
|
+
return sock.semanticToStrict(schema);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
throw new Error("To use the `nullability.errorHandlingClient` option, you must install the 'graphql-sock' package.");
|
|
262
|
+
}
|
|
263
|
+
};
|
|
251
264
|
var add_typename_selection_document_transform_js_1 = require("./add-typename-selection-document-transform.js");
|
|
252
265
|
Object.defineProperty(exports, "addTypenameSelectionDocumentTransform", { enumerable: true, get: function () { return add_typename_selection_document_transform_js_1.addTypenameSelectionDocumentTransform; } });
|
|
@@ -6,6 +6,8 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const documents_1 = require("@graphql-tools/documents");
|
|
7
7
|
const crypto = tslib_1.__importStar(require("crypto"));
|
|
8
8
|
const graphql_1 = require("graphql");
|
|
9
|
+
const CLIENT_DIRECTIVE_NAME = 'client';
|
|
10
|
+
const CONNECTION_DIRECTIVE_NAME = 'connection';
|
|
9
11
|
/**
|
|
10
12
|
* This function generates a hash from a document node.
|
|
11
13
|
*/
|
|
@@ -30,12 +32,22 @@ function normalizeAndPrintDocumentNode(documentNode) {
|
|
|
30
32
|
*/
|
|
31
33
|
const sanitizedDocument = (0, graphql_1.visit)(documentNode, {
|
|
32
34
|
[graphql_1.Kind.FIELD](field) {
|
|
33
|
-
if (field.directives?.some(directive => directive.name.value ===
|
|
35
|
+
if (field.directives?.some(directive => directive.name.value === CLIENT_DIRECTIVE_NAME)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
[graphql_1.Kind.FRAGMENT_SPREAD](spread) {
|
|
40
|
+
if (spread.directives?.some(directive => directive.name.value === CLIENT_DIRECTIVE_NAME)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[graphql_1.Kind.INLINE_FRAGMENT](fragment) {
|
|
45
|
+
if (fragment.directives?.some(directive => directive.name.value === CLIENT_DIRECTIVE_NAME)) {
|
|
34
46
|
return null;
|
|
35
47
|
}
|
|
36
48
|
},
|
|
37
49
|
[graphql_1.Kind.DIRECTIVE](directive) {
|
|
38
|
-
if (directive.name.value ===
|
|
50
|
+
if (directive.name.value === CONNECTION_DIRECTIVE_NAME) {
|
|
39
51
|
return null;
|
|
40
52
|
}
|
|
41
53
|
},
|
package/esm/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as typedDocumentNodePlugin from '@graphql-codegen/typed-document-node';
|
|
|
4
4
|
import * as typescriptPlugin from '@graphql-codegen/typescript';
|
|
5
5
|
import * as typescriptOperationPlugin from '@graphql-codegen/typescript-operations';
|
|
6
6
|
import { ClientSideBaseVisitor, DocumentMode } from '@graphql-codegen/visitor-plugin-common';
|
|
7
|
+
import { parse, printSchema } from 'graphql';
|
|
7
8
|
import * as fragmentMaskingPlugin from './fragment-masking-plugin.js';
|
|
8
9
|
import { generateDocumentHash, normalizeAndPrintDocumentNode } from './persisted-documents.js';
|
|
9
10
|
import { processSources } from './process-sources.js';
|
|
@@ -11,7 +12,7 @@ export { default as babelOptimizerPlugin } from './babel.js';
|
|
|
11
12
|
const isOutputFolderLike = (baseOutputDir) => baseOutputDir.endsWith('/');
|
|
12
13
|
export const preset = {
|
|
13
14
|
prepareDocuments: (outputFilePath, outputSpecificDocuments) => [...outputSpecificDocuments, `!${outputFilePath}`],
|
|
14
|
-
buildGeneratesSection: options => {
|
|
15
|
+
buildGeneratesSection: async (options) => {
|
|
15
16
|
if (!isOutputFolderLike(options.baseOutputDir)) {
|
|
16
17
|
throw new Error('[client-preset] target output should be a directory, ex: "src/gql/". Make sure you add "/" at the end of the directory path');
|
|
17
18
|
}
|
|
@@ -19,6 +20,10 @@ export const preset = {
|
|
|
19
20
|
throw new Error('[client-preset] providing typescript-based `plugins` with `preset: "client" leads to duplicated generated types');
|
|
20
21
|
}
|
|
21
22
|
const isPersistedOperations = !!options.presetConfig?.persistedDocuments;
|
|
23
|
+
if (options.config.nullability?.errorHandlingClient) {
|
|
24
|
+
options.schemaAst = await semanticToStrict(options.schemaAst);
|
|
25
|
+
options.schema = parse(printSchema(options.schemaAst));
|
|
26
|
+
}
|
|
22
27
|
const reexports = [];
|
|
23
28
|
// the `client` preset is restricting the config options inherited from `typescript`, `typescript-operations` and others.
|
|
24
29
|
const forwardedConfig = {
|
|
@@ -31,12 +36,16 @@ export const preset = {
|
|
|
31
36
|
arrayInputCoercion: options.config.arrayInputCoercion,
|
|
32
37
|
enumsAsTypes: options.config.enumsAsTypes,
|
|
33
38
|
enumsAsConst: options.config.enumsAsConst,
|
|
39
|
+
enumValues: options.config.enumValues,
|
|
34
40
|
futureProofEnums: options.config.futureProofEnums,
|
|
35
41
|
dedupeFragments: options.config.dedupeFragments,
|
|
36
42
|
nonOptionalTypename: options.config.nonOptionalTypename,
|
|
37
43
|
avoidOptionals: options.config.avoidOptionals,
|
|
38
44
|
documentMode: options.config.documentMode,
|
|
39
45
|
skipTypeNameForRoot: options.config.skipTypeNameForRoot,
|
|
46
|
+
onlyOperationTypes: options.config.onlyOperationTypes,
|
|
47
|
+
onlyEnums: options.config.onlyEnums,
|
|
48
|
+
customDirectives: options.config.customDirectives,
|
|
40
49
|
};
|
|
41
50
|
const visitor = new ClientSideBaseVisitor(options.schemaAst, [], options.config, options.config);
|
|
42
51
|
let fragmentMaskingConfig = null;
|
|
@@ -103,12 +112,7 @@ export const preset = {
|
|
|
103
112
|
}
|
|
104
113
|
const plugins = [
|
|
105
114
|
{ [`add`]: { content: `/* eslint-disable */` } },
|
|
106
|
-
{
|
|
107
|
-
[`typescript`]: {
|
|
108
|
-
onlyEnumTypes: true,
|
|
109
|
-
onlyOperationTypes: true,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
115
|
+
{ [`typescript`]: {} },
|
|
112
116
|
{ [`typescript-operations`]: {} },
|
|
113
117
|
{
|
|
114
118
|
[`typed-document-node`]: {
|
|
@@ -243,4 +247,13 @@ function createDeferred() {
|
|
|
243
247
|
});
|
|
244
248
|
return d;
|
|
245
249
|
}
|
|
250
|
+
const semanticToStrict = async (schema) => {
|
|
251
|
+
try {
|
|
252
|
+
const sock = await import('graphql-sock');
|
|
253
|
+
return sock.semanticToStrict(schema);
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
throw new Error("To use the `nullability.errorHandlingClient` option, you must install the 'graphql-sock' package.");
|
|
257
|
+
}
|
|
258
|
+
};
|
|
246
259
|
export { addTypenameSelectionDocumentTransform } from './add-typename-selection-document-transform.js';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { printExecutableGraphQLDocument } from '@graphql-tools/documents';
|
|
2
2
|
import * as crypto from 'crypto';
|
|
3
3
|
import { Kind, visit } from 'graphql';
|
|
4
|
+
const CLIENT_DIRECTIVE_NAME = 'client';
|
|
5
|
+
const CONNECTION_DIRECTIVE_NAME = 'connection';
|
|
4
6
|
/**
|
|
5
7
|
* This function generates a hash from a document node.
|
|
6
8
|
*/
|
|
@@ -25,12 +27,22 @@ export function normalizeAndPrintDocumentNode(documentNode) {
|
|
|
25
27
|
*/
|
|
26
28
|
const sanitizedDocument = visit(documentNode, {
|
|
27
29
|
[Kind.FIELD](field) {
|
|
28
|
-
if (field.directives?.some(directive => directive.name.value ===
|
|
30
|
+
if (field.directives?.some(directive => directive.name.value === CLIENT_DIRECTIVE_NAME)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
[Kind.FRAGMENT_SPREAD](spread) {
|
|
35
|
+
if (spread.directives?.some(directive => directive.name.value === CLIENT_DIRECTIVE_NAME)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
[Kind.INLINE_FRAGMENT](fragment) {
|
|
40
|
+
if (fragment.directives?.some(directive => directive.name.value === CLIENT_DIRECTIVE_NAME)) {
|
|
29
41
|
return null;
|
|
30
42
|
}
|
|
31
43
|
},
|
|
32
44
|
[Kind.DIRECTIVE](directive) {
|
|
33
|
-
if (directive.name.value ===
|
|
45
|
+
if (directive.name.value === CONNECTION_DIRECTIVE_NAME) {
|
|
34
46
|
return null;
|
|
35
47
|
}
|
|
36
48
|
},
|
package/package.json
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/client-preset",
|
|
3
|
-
"version": "5.0.0-alpha-
|
|
3
|
+
"version": "5.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
4
4
|
"description": "GraphQL Code Generator preset for client.",
|
|
5
|
+
"peerDependenciesMeta": {
|
|
6
|
+
"graphql-sock": {
|
|
7
|
+
"optional": true
|
|
8
|
+
}
|
|
9
|
+
},
|
|
5
10
|
"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"
|
|
11
|
+
"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",
|
|
12
|
+
"graphql-sock": "^1.0.0"
|
|
7
13
|
},
|
|
8
14
|
"dependencies": {
|
|
9
15
|
"@babel/helper-plugin-utils": "^7.20.2",
|
|
10
16
|
"@babel/template": "^7.20.7",
|
|
11
|
-
"@graphql-codegen/add": "
|
|
12
|
-
"@graphql-codegen/typed-document-node": "
|
|
13
|
-
"@graphql-codegen/typescript": "
|
|
14
|
-
"@graphql-codegen/typescript-operations": "
|
|
15
|
-
"@graphql-codegen/gql-tag-operations": "
|
|
16
|
-
"@graphql-codegen/plugin-helpers": "
|
|
17
|
-
"@graphql-codegen/visitor-plugin-common": "
|
|
17
|
+
"@graphql-codegen/add": "6.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
18
|
+
"@graphql-codegen/typed-document-node": "6.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
19
|
+
"@graphql-codegen/typescript": "5.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
20
|
+
"@graphql-codegen/typescript-operations": "5.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
21
|
+
"@graphql-codegen/gql-tag-operations": "5.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
22
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
23
|
+
"@graphql-codegen/visitor-plugin-common": "6.0.0-alpha-20250806120945-d5b15566e4de55fa06797f61b89b4e561e65e043",
|
|
18
24
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
19
25
|
"@graphql-tools/documents": "^1.0.0",
|
|
20
26
|
"@graphql-tools/utils": "^10.0.0",
|
package/typings/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import { DocumentNode } from 'graphql';
|
|
2
|
+
import { type DocumentNode } from 'graphql';
|
|
3
3
|
export { default as babelOptimizerPlugin } from './babel.cjs';
|
|
4
4
|
export type FragmentMaskingConfig = {
|
|
5
5
|
/** @description Name of the function that should be used for unmasking a masked fragment property.
|
|
@@ -13,7 +13,7 @@ export type ClientPresetConfig = {
|
|
|
13
13
|
* @exampleMarkdown
|
|
14
14
|
* ```tsx
|
|
15
15
|
* const config = {
|
|
16
|
-
* schema: 'https://
|
|
16
|
+
* schema: 'https://graphql.org/graphql/',
|
|
17
17
|
* documents: ['src/**\/*.tsx', '!src\/gql/**\/*'],
|
|
18
18
|
* generates: {
|
|
19
19
|
* './src/gql/': {
|
|
@@ -37,7 +37,7 @@ export type ClientPresetConfig = {
|
|
|
37
37
|
* @exampleMarkdown
|
|
38
38
|
* ```tsx
|
|
39
39
|
* const config = {
|
|
40
|
-
* schema: 'https://
|
|
40
|
+
* schema: 'https://graphql.org/graphql/',
|
|
41
41
|
* documents: ['src/**\/*.tsx', '!src\/gql/**\/*'],
|
|
42
42
|
* generates: {
|
|
43
43
|
* './src/gql/': {
|
package/typings/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import { DocumentNode } from 'graphql';
|
|
2
|
+
import { type DocumentNode } from 'graphql';
|
|
3
3
|
export { default as babelOptimizerPlugin } from './babel.js';
|
|
4
4
|
export type FragmentMaskingConfig = {
|
|
5
5
|
/** @description Name of the function that should be used for unmasking a masked fragment property.
|
|
@@ -13,7 +13,7 @@ export type ClientPresetConfig = {
|
|
|
13
13
|
* @exampleMarkdown
|
|
14
14
|
* ```tsx
|
|
15
15
|
* const config = {
|
|
16
|
-
* schema: 'https://
|
|
16
|
+
* schema: 'https://graphql.org/graphql/',
|
|
17
17
|
* documents: ['src/**\/*.tsx', '!src\/gql/**\/*'],
|
|
18
18
|
* generates: {
|
|
19
19
|
* './src/gql/': {
|
|
@@ -37,7 +37,7 @@ export type ClientPresetConfig = {
|
|
|
37
37
|
* @exampleMarkdown
|
|
38
38
|
* ```tsx
|
|
39
39
|
* const config = {
|
|
40
|
-
* schema: 'https://
|
|
40
|
+
* schema: 'https://graphql.org/graphql/',
|
|
41
41
|
* documents: ['src/**\/*.tsx', '!src\/gql/**\/*'],
|
|
42
42
|
* generates: {
|
|
43
43
|
* './src/gql/': {
|