Skip to content

Commit

Permalink
fixing schema caching for multi-schema workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Sissons committed Nov 15, 2018
1 parent 774f91b commit 325873f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change log

### vNEXT

- Fix support for multi-schema workspaces [#179](https://github.com/apollographql/eslint-plugin-graphql/pull/179) by [Pat Sissons](https://github.com/patsissons)

### v3.0.0

- BREAKING: The `required-fields` rule has been significantly changed to make it a completely reliable method of ensuring an `id` field (or any other field name) is always requested when available. [PR #199](https://github.com/apollographql/eslint-plugin-graphql/pull/199) Here is the behavior, let's say we are requiring field `id`:
Expand Down
23 changes: 17 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,9 @@ export const rules = {
};

const schemaCache = {};
const projectCache = {};

function parseOptions(optionGroup, context) {
const cacheHit = schemaCache[JSON.stringify(optionGroup)];
if (cacheHit) {
return cacheHit;
}
const {
schemaJson, // Schema via JSON object
schemaJsonFilepath, // Or Schema via absolute filepath
Expand All @@ -241,6 +238,11 @@ function parseOptions(optionGroup, context) {
validators: validatorNamesOption,
} = optionGroup;

const cacheHit = schemaCache[JSON.stringify(optionGroup)];
if (cacheHit && env !== 'literal') {
return cacheHit;
}

// Validate and unpack schema
let schema;
if (schemaJson) {
Expand All @@ -261,15 +263,24 @@ function parseOptions(optionGroup, context) {
} else {
projectConfig = config.getConfigForFile(context.getFilename());
}
schema = projectConfig.getSchema();
if (projectConfig) {
const key = `${config.configPath}[${projectConfig.projectName}]`
schema = projectCache[key];
if (!schema) {
schema = projectConfig.getSchema();
projectCache[key] = schema;
}
}
if (cacheHit) {
return {...cacheHit, schema};
}
} catch (e) {
if (e instanceof ConfigNotFoundError) {
throw new Error('Must provide .graphqlconfig file or pass in `schemaJson` option ' +
'with schema object or `schemaJsonFilepath` with absolute path to the json file.');
}
throw e;
}

}

// Validate env
Expand Down

0 comments on commit 325873f

Please sign in to comment.