question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cost validator throws duplicate error for an invalid input

See original GitHub issue

Discussed 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:open
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rafalpcommented, Nov 18, 2022

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.

1reaction
rafalpcommented, Nov 17, 2022

Punting this from 0.17, I don’t feel this is big issue that should prevent the release.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found