forked from gridsome/gridsome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(graphql): don’t fix unknown variable types
- Loading branch information
Showing
3 changed files
with
28 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
const { parse, visit, validate, specifiedRules } = require('graphql') | ||
const { parse, validate, specifiedRules } = require('graphql') | ||
const { fixIncorrectVariableUsage } = require('../../../graphql/transforms') | ||
|
||
module.exports = (schema, query) => { | ||
return validate(schema, parseQuery(schema, query), specifiedRules) | ||
} | ||
const FixIncorrectVariableUsage = context => { | ||
const schema = context.getSchema() | ||
const ast = context.getDocument() | ||
|
||
function parseQuery (schema, query) { | ||
const ast = parse(query) | ||
|
||
return visit(ast, { | ||
return { | ||
VariableDefinition (variableDef) { | ||
if (variableDef.variable.name.value !== 'page') { | ||
if (variableDef.variable.name.value === 'id') { | ||
// TODO: remove this fix before 1.0 | ||
fixIncorrectVariableUsage(schema, ast, variableDef) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
const rules = [FixIncorrectVariableUsage, ...specifiedRules] | ||
|
||
module.exports = (schema, query) => { | ||
return validate(schema, parse(query), rules) | ||
} |