Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint for required fields [WIP] #50

Merged
merged 6 commits into from
May 1, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bind validators
rgoldfinger committed May 1, 2017
commit decc7c2ec52b00438e03c19e72a16768397b27e8
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -59,11 +59,12 @@ function createRule(context, optionParser) {
const tagRules = [];
for (const optionGroup of context.options) {
const {schema, env, tagName, validators} = optionParser(optionGroup);
const boundValidators = validators.map(v => (ctx) => v(ctx, optionGroup));
if (tagNames.has(tagName)) {
throw new Error('Multiple options for GraphQL tag ' + tagName);
}
tagNames.add(tagName);
tagRules.push({schema, env, tagName, validators});
tagRules.push({schema, env, tagName, validators: boundValidators});
}
return {
TaggedTemplateExpression(node) {
4 changes: 2 additions & 2 deletions src/rules.js
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@ export function OperationsMustHaveNames(context) {
};
}

export function RequiredFields(context) {
export function RequiredFields(context, options) {
return {
Field(node, _ctx, _schema, _env, _validators, options) {
Field(node) {
const def = context.getFieldDef();
const { requiredFields } = options;
requiredFields.forEach(field => {