-
Notifications
You must be signed in to change notification settings - Fork 24
allow formatErrorMessage callback #3
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
Changes from 6 commits
4226b58
b3e65aa
a208710
59e4afd
b444cb3
eff4dee
a2f8182
109841b
5ec7917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,9 +149,14 @@ export function createComplexityLimitRule(maxCost, options = {}) { | |
} | ||
|
||
if (node.kind === 'Document') { | ||
if (visitor.getCost() > maxCost) { | ||
const cost = visitor.getCost(); | ||
if (options.onCost) options.onCost(cost); | ||
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. maybe also pass the query as arg to onCost? 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. @taion I still think passing the document node might be useful to both these functions. we maybe want to log queries that fail in prod as well? 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. split out these properties before passing down to visitor |
||
if (cost > maxCost) { | ||
const errorMessage = options.formatErrorMessage ? | ||
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. just default |
||
options.formatErrorMessage(cost) : | ||
`query exceeds complexity limit. Cost: ${cost}`; | ||
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. we should absolutely not always return the cost here; the calculation may be a private detail |
||
context.reportError(new GraphQLError( | ||
'query exceeds complexity limit', [node], | ||
errorMessage, [node], | ||
)); | ||
} | ||
} | ||
|
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.
these examples are sort of weak (plus don't follow eslint guidelines). also the graf above needs to explain these options.