-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix mutation name #15
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,12 +58,43 @@ const checkWrongName = (text, node, messages, name) => { | |
} | ||
}; | ||
|
||
function getMutationNames(ast) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you place this function in a new file in the "lib" folder, maybe helpers.js or mutations.js, whatever you think is best. |
||
const mutationNames = []; | ||
|
||
visit(ast, { | ||
ObjectTypeExtension(node) { | ||
if ( | ||
node.name.value !== 'Mutation' || | ||
node.name.value === 'GraphQLMutation' | ||
) { | ||
return; | ||
} | ||
visit(node, { | ||
FieldDefinition(node) { | ||
mutationNames.push(node.type.name.value); | ||
} | ||
}); | ||
}, | ||
ObjectTypeDefinition(node) { | ||
if ( | ||
node.name.value === 'Mutation' || | ||
node.name.value === 'GraphQLMutation' | ||
) { | ||
mutationNames.push(node.name.value); | ||
} | ||
} | ||
}); | ||
return mutationNames; | ||
} | ||
|
||
module.exports = function(ast, text) { | ||
const messages = []; | ||
|
||
const mutationNames = getMutationNames(ast); | ||
|
||
visit(ast, { | ||
ObjectTypeDefinition(node) { | ||
if (node.name.value !== 'GraphQLMutation') { | ||
if (mutationNames.indexOf(node.name.value) < 0) { | ||
return; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,43 @@ const getMessage = (text, name, start) => { | |
}; | ||
}; | ||
|
||
function getMutationNames(ast) { | ||
const mutationNames = []; | ||
|
||
visit(ast, { | ||
ObjectTypeExtension(node) { | ||
if ( | ||
node.name.value !== 'Mutation' || | ||
node.name.value === 'GraphQLMutation' | ||
) { | ||
return; | ||
} | ||
visit(node, { | ||
FieldDefinition(node) { | ||
mutationNames.push(node.type.name.value); | ||
} | ||
}); | ||
}, | ||
ObjectTypeDefinition(node) { | ||
if ( | ||
node.name.value === 'Mutation' || | ||
node.name.value === 'GraphQLMutation' | ||
) { | ||
mutationNames.push(node.name.value); | ||
} | ||
} | ||
}); | ||
return mutationNames; | ||
} | ||
|
||
module.exports = function(ast, text) { | ||
const messages = []; | ||
|
||
const mutationNames = getMutationNames(ast); | ||
|
||
visit(ast, { | ||
ObjectTypeDefinition(node) { | ||
if (node.name.value !== 'GraphQLMutation') { | ||
if (mutationNames.indexOf(node.name.value) < 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And lastly, would you be able to add a test for this new "extend type Mutation" in https://github.com/happylinks/gqlint/blob/master/tests/rules/removedelete.mutations.test.js and maybe also in https://github.com/happylinks/gqlint/blob/master/tests/rules/singular.mutations.test.js just to be sure. |
||
return; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the changes from this file? They're not related to your pr.