Skip to content

Commit 7e248ce

Browse files
Kristján Oddssonjnwng
Kristján Oddsson
authored andcommitted
Cache for parsing the schema (#137)
* simple cache for schema parsing * add CHANGELOG entry for schema cache
1 parent b00a571 commit 7e248ce

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change log
22
### vNEXT
33
- Retrieves `.graphqlconfig` relative to the file being linted, which re-enables support for `vscode-eslint` using `.graphqlconfig` in [#108](https://github.com/apollographql/eslint-plugin-graphql/pull/108) by [Jon Wong][https://github.com/jnwng/]
4+
- Cache schema reading/parsing results each time a rule is created in [#137](https://github.com/apollographql/eslint-plugin-graphql/pull/137) by [Kristján Oddsson](https://github.com/koddsson)
45

56
### v2.0.0
67
- Add support for `graphql-js@^0.12.0` and `graphql-js@^0.13.0` in [Jon Wong](https://github.com/jnwng/)[#119] (https://github.com/apollographql/eslint-plugin-graphql/pull/93)

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,13 @@ export const rules = {
243243
},
244244
};
245245

246+
const schemaCache = {};
247+
246248
function parseOptions(optionGroup, context) {
249+
const cacheHit = schemaCache[JSON.stringify(optionGroup)];
250+
if (cacheHit) {
251+
return cacheHit;
252+
}
247253
const {
248254
schemaJson, // Schema via JSON object
249255
schemaJsonFilepath, // Or Schema via absolute filepath
@@ -322,7 +328,9 @@ function parseOptions(optionGroup, context) {
322328
return require(`graphql/validation/rules/${name}`)[name];
323329
}
324330
});
325-
return {schema, env, tagName, validators};
331+
const results = {schema, env, tagName, validators};
332+
schemaCache[JSON.stringify(optionGroup)] = results;
333+
return results;
326334
}
327335

328336
function initSchema(json) {

0 commit comments

Comments
 (0)