Cost validator throws duplicate error for an invalid input
See original GitHub issueDiscussed in https://github.com/mirumee/ariadne/discussions/934
<div type='discussions-op-text'>Originally posted by jayeshv September 30, 2022 Consider the following app
from ariadne import QueryType, ScalarType, gql, make_executable_schema
from ariadne.asgi import GraphQL
from ariadne.validation import cost_directive, cost_validator
type_defs = gql("""
scalar MyScalar
type Query {
test(myInput: MyScalar!): String
}
""")
query = QueryType()
my_scalar = ScalarType("MyScalar")
@my_scalar.value_parser
def validate_myscalar(value):
if value == "a":
raise ValueError("Invalid myscalar")
return value
@query.field("test")
def resolve_hello(_, info, **kw):
return "hello"
schema = make_executable_schema([type_defs, cost_directive], query, my_scalar)
app = GraphQL(schema, debug=False, validation_rules=[cost_validator(maximum_cost=5)])
for the following query, it generates two error objects.
query test {
test(myInput: "a")
}
{
"error": {
"errors": [
{
"message": "Argument 'myInput' has invalid value \"a\".\n\nGraphQL request:2:17\n1 | query test {\n2 | test(myInput: \"a\")\n | ^\n3 | }"
},
{
"message": "Expected value of type 'MyScalar!', found \"a\"; Invalid myscalar",
"locations": [
{
"line": 2,
"column": 17
}
]
}
]
}
}
Isn’t the first error created by the cost_validator a redundant one? This duplicate error happens only with the extra validator. ariadne version 0.16.1</div>
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Which status code should I use for failed validations or invalid ...
A duplicate in the database should be a 409 CONFLICT . I recommend using 422 UNPROCESSABLE ENTITY for validation errors.
Read more >[mlogc] SecAuditLog throwing error "Invalid input" for ... - GitHub
It seems like this is a duplicate with #1498. For libModSecurity we suggest using the HTTPS transport by setting the SecAuditLogType to "HTTPS" ......
Read more >Validation of the input parameter in caller: code duplication?
I am thinking about some arguments: when the treating of invalid variable can vary, is good to validate it in caller side (e.g...
Read more >CWE-20: Improper Input Validation (4.9) - MITRE
The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required...
Read more >Full Stack Error Handling with GraphQL and Apollo
networkError : Errors that are thrown outside of your resolvers. If networkError is present in your response, it means your entire query was ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Query cost validator requires extra setup to support variables, its documented here:
https://ariadnegraphql.org/docs/query-validators#exposing-query-variables-to-cost_validator
I guess we should update the docs to make validators setup dynamic mandatory for Query Cost.
Punting this from 0.17, I don’t feel this is big issue that should prevent the release.