@graphql-codegen/core 2.5.1-alpha-bbecef04a.0 → 2.6.0-alpha-a52c122aa.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,10 @@ function hasFederationSpec(schemaOrAST) {
103
103
  }
104
104
  return false;
105
105
  }
106
+ function extractHashFromSchema(schema) {
107
+ var _a;
108
+ return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
109
+ }
106
110
 
107
111
  async function codegen(options) {
108
112
  var _a;
@@ -149,13 +153,22 @@ async function codegen(options) {
149
153
  ignored.push(...utils.asArray(skipDocumentsValidation.ignoreRules));
150
154
  }
151
155
  const extraFragments = pickFlag('externalFragments', options.config) || [];
152
- const errors = await profiler.run(() => utils.validateGraphQlDocuments(schemaInstance, [
153
- ...documents,
154
- ...extraFragments.map(f => ({
156
+ const errors = await profiler.run(() => {
157
+ const fragments = extraFragments.map(f => ({
155
158
  location: f.importFrom,
156
159
  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');
160
+ }));
161
+ const rules = graphql.specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
162
+ const schemaHash = extractHashFromSchema(schemaInstance);
163
+ if (!schemaHash || !options.cache || !documents.some(d => typeof d.hash !== 'string')) {
164
+ return utils.validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules);
165
+ }
166
+ const cacheKey = [schemaHash]
167
+ .concat(documents.map(doc => doc.hash))
168
+ .concat(JSON.stringify(fragments))
169
+ .join(',');
170
+ return options.cache('documents-validation', cacheKey, () => utils.validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules));
171
+ }, 'Validate documents against schema');
159
172
  utils.checkValidationErrors(errors);
160
173
  }
161
174
  const prepend = new Set();
package/index.mjs CHANGED
@@ -99,6 +99,10 @@ function hasFederationSpec(schemaOrAST) {
99
99
  }
100
100
  return false;
101
101
  }
102
+ function extractHashFromSchema(schema) {
103
+ var _a;
104
+ return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
105
+ }
102
106
 
103
107
  async function codegen(options) {
104
108
  var _a;
@@ -145,13 +149,22 @@ async function codegen(options) {
145
149
  ignored.push(...asArray(skipDocumentsValidation.ignoreRules));
146
150
  }
147
151
  const extraFragments = pickFlag('externalFragments', options.config) || [];
148
- const errors = await profiler.run(() => validateGraphQlDocuments(schemaInstance, [
149
- ...documents,
150
- ...extraFragments.map(f => ({
152
+ const errors = await profiler.run(() => {
153
+ const fragments = extraFragments.map(f => ({
151
154
  location: f.importFrom,
152
155
  document: { kind: Kind.DOCUMENT, definitions: [f.node] },
153
- })),
154
- ], specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)))), 'Validate documents against schema');
156
+ }));
157
+ const rules = specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
158
+ const schemaHash = extractHashFromSchema(schemaInstance);
159
+ if (!schemaHash || !options.cache || !documents.some(d => typeof d.hash !== 'string')) {
160
+ return validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules);
161
+ }
162
+ const cacheKey = [schemaHash]
163
+ .concat(documents.map(doc => doc.hash))
164
+ .concat(JSON.stringify(fragments))
165
+ .join(',');
166
+ return options.cache('documents-validation', cacheKey, () => validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules));
167
+ }, 'Validate documents against schema');
155
168
  checkValidationErrors(errors);
156
169
  }
157
170
  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-a52c122aa.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-a52c122aa.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;