@graphql-codegen/core 2.5.1-alpha-bbecef04a.0 → 2.6.0-alpha-7c50b8781.0

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/index.js CHANGED
@@ -103,6 +103,13 @@ function hasFederationSpec(schemaOrAST) {
103
103
  }
104
104
  return false;
105
105
  }
106
+ function extractHashFromSchema(schema) {
107
+ var _a;
108
+ if (!schema.extensions) {
109
+ schema.extensions = {};
110
+ }
111
+ return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
112
+ }
106
113
 
107
114
  async function codegen(options) {
108
115
  var _a;
@@ -149,13 +156,22 @@ async function codegen(options) {
149
156
  ignored.push(...utils.asArray(skipDocumentsValidation.ignoreRules));
150
157
  }
151
158
  const extraFragments = pickFlag('externalFragments', options.config) || [];
152
- const errors = await profiler.run(() => utils.validateGraphQlDocuments(schemaInstance, [
153
- ...documents,
154
- ...extraFragments.map(f => ({
159
+ const errors = await profiler.run(() => {
160
+ const fragments = extraFragments.map(f => ({
155
161
  location: f.importFrom,
156
162
  document: { kind: graphql.Kind.DOCUMENT, definitions: [f.node] },
157
- })),
158
- ], graphql.specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)))), 'Validate documents against schema');
163
+ }));
164
+ const rules = graphql.specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
165
+ const schemaHash = extractHashFromSchema(schemaInstance);
166
+ if (!schemaHash || !options.cache || documents.some(d => typeof d.hash !== 'string')) {
167
+ return utils.validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules);
168
+ }
169
+ const cacheKey = [schemaHash]
170
+ .concat(documents.map(doc => doc.hash))
171
+ .concat(JSON.stringify(fragments))
172
+ .join(',');
173
+ return options.cache('documents-validation', cacheKey, () => utils.validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules));
174
+ }, 'Validate documents against schema');
159
175
  utils.checkValidationErrors(errors);
160
176
  }
161
177
  const prepend = new Set();
package/index.mjs CHANGED
@@ -99,6 +99,13 @@ function hasFederationSpec(schemaOrAST) {
99
99
  }
100
100
  return false;
101
101
  }
102
+ function extractHashFromSchema(schema) {
103
+ var _a;
104
+ if (!schema.extensions) {
105
+ schema.extensions = {};
106
+ }
107
+ return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
108
+ }
102
109
 
103
110
  async function codegen(options) {
104
111
  var _a;
@@ -145,13 +152,22 @@ async function codegen(options) {
145
152
  ignored.push(...asArray(skipDocumentsValidation.ignoreRules));
146
153
  }
147
154
  const extraFragments = pickFlag('externalFragments', options.config) || [];
148
- const errors = await profiler.run(() => validateGraphQlDocuments(schemaInstance, [
149
- ...documents,
150
- ...extraFragments.map(f => ({
155
+ const errors = await profiler.run(() => {
156
+ const fragments = extraFragments.map(f => ({
151
157
  location: f.importFrom,
152
158
  document: { kind: Kind.DOCUMENT, definitions: [f.node] },
153
- })),
154
- ], specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)))), 'Validate documents against schema');
159
+ }));
160
+ const rules = specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
161
+ const schemaHash = extractHashFromSchema(schemaInstance);
162
+ if (!schemaHash || !options.cache || documents.some(d => typeof d.hash !== 'string')) {
163
+ return validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules);
164
+ }
165
+ const cacheKey = [schemaHash]
166
+ .concat(documents.map(doc => doc.hash))
167
+ .concat(JSON.stringify(fragments))
168
+ .join(',');
169
+ return options.cache('documents-validation', cacheKey, () => validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules));
170
+ }, 'Validate documents against schema');
155
171
  checkValidationErrors(errors);
156
172
  }
157
173
  const prepend = new Set();
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@graphql-codegen/core",
3
- "version": "2.5.1-alpha-bbecef04a.0",
3
+ "version": "2.6.0-alpha-7c50b8781.0",
4
4
  "peerDependencies": {
5
5
  "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
6
  },
7
7
  "dependencies": {
8
- "@graphql-codegen/plugin-helpers": "2.4.1-alpha-bbecef04a.0",
8
+ "@graphql-codegen/plugin-helpers": "2.5.0-alpha-7c50b8781.0",
9
9
  "@graphql-tools/schema": "^8.1.2",
10
10
  "@graphql-tools/utils": "^8.1.1",
11
11
  "tslib": "~2.3.0"
package/utils.d.ts CHANGED
@@ -7,3 +7,4 @@ export declare function shouldValidateDuplicateDocuments(skipDocumentsValidation
7
7
  export declare function shouldValidateDocumentsAgainstSchema(skipDocumentsValidationOption: Types.GenerateOptions['skipDocumentsValidation']): boolean;
8
8
  export declare function getSkipDocumentsValidationOption(options: Types.GenerateOptions): Types.SkipDocumentsValidationOptions;
9
9
  export declare function hasFederationSpec(schemaOrAST: GraphQLSchema | DocumentNode): boolean;
10
+ export declare function extractHashFromSchema(schema: GraphQLSchema): string | null;