Skip to content

Commit

Permalink
Adding support for project-relative configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
jnwng committed Apr 15, 2018
1 parent 40a2c13 commit 32c6095
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const rules = {
}
},
},
create: (context) => createRule(context, parseOptions)
create: (context) => createRule(context, (optionGroup) => parseOptions(optionGroup, context))
},
'named-operations': {
meta: {
Expand All @@ -167,7 +167,7 @@ export const rules = {
return createRule(context, (optionGroup) => parseOptions({
validators: ['OperationsMustHaveNames'],
...optionGroup,
}));;
}, context));
},
},
'required-fields': {
Expand Down Expand Up @@ -219,7 +219,7 @@ export const rules = {
return createRule(context, (optionGroup) => parseOptions({
validators: ['typeNamesShouldBeCapitalized'],
...optionGroup,
}));
}, context));
},
},
'no-deprecated-fields': {
Expand All @@ -237,7 +237,7 @@ export const rules = {
return createRule(context, (optionGroup) => parseOptions({
validators: ['noDeprecatedFields'],
...optionGroup,
}));
}, context));
},
},
};
Expand All @@ -264,7 +264,16 @@ function parseOptions(optionGroup, context) {
} else {
try {
const config = getGraphQLConfig();
schema = config.getConfigForFile(context.getFilename()).getSchema();
let projectConfig;
if (projectName) {
projectConfig = config.getProjects()[projectName];
if (!projectConfig) {
throw new Error(`Project with name "${projectName}" not found in ${config.configPath}.`);
}
} else {
projectConfig = config.getConfigForFile(context.getFilename());
}
schema = projectConfig.getSchema();
} catch (e) {
if (e instanceof ConfigNotFoundError) {
throw new Error('Must provide .graphqlconfig file or pass in `schemaJson` option ' +
Expand Down
1 change: 0 additions & 1 deletion test/graphqlconfig/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ describe('graphqlconfig support', () => {
{ projectName: 'swapi', tagName: 'swapi' },
];


beforeEach(() => {
process.chdir('test/graphqlconfig/multiproject');
})
Expand Down

0 comments on commit 32c6095

Please sign in to comment.