You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a query with gql.gql(), the query string is checked for invalid arguments, and raises an exception if any are found. (expected behavior)
When creating a query with gql.dsl.dsl_gql(), the arguments are not checked, causing unexpected return values. (unexpected behavior)
I've been able to recreate this using the countries api used in the docs.
To Reproduce
Jump to step 5 to see the actual improper behavior.
Set up the transport/client.
importjsonimportgqlfromgql.transport.requestsimportRequestsHTTPTransportasTransportfromgqlimportdslurl="https://countries.trevorblades.com/"transport=Transport(url=url)
client=gql.Client(transport=transport, fetch_schema_from_transport=True)
# Fetch the schema (lemme know if there's a recommended approach for this).client.connect_sync()
client.close_sync()
ds=dsl.DSLSchema(client.schema)
Poking at this a bit more (after finding gql.dsl.print_ast), it looks like DSL silently cleanses your query of anything it doesn't recognize, so the example above:
This also happens in some (but not all) cases where an incorrect type is provided as a value. I've found that passing a list where a string is expected returns a very long traceback, ending with this:
inserialize_string(output_value)
174# do not serialize builtin types as strings, but allow serialization of custom 175 # types via their `__str__` method176iftype(output_value).__module__=="builtins":
-->177raiseGraphQLError("String cannot represent value: "+inspect(output_value))
178returnstr(output_value)
GraphQLError: Stringcannotrepresentvalue: ['AN']
However, passing a string or a dict where a list of dict is expected results in an empty list in the query. Differently again, passing a string where a list of string is expected is accepted. I don't know if this is a gql quirk or a GraphQL quirk.
Describe the bug
gql.gql()
, the query string is checked for invalid arguments, and raises an exception if any are found. (expected behavior)gql.dsl.dsl_gql()
, the arguments are not checked, causing unexpected return values. (unexpected behavior)I've been able to recreate this using the countries api used in the docs.
To Reproduce
Jump to step 5 to see the actual improper behavior.
Set up the transport/client.
Run a good query using strings.
Result:
Run a bad query using strings. The only change here is using
'AN'
directly as an argument tocode
, instead of providing theeq
directive.Result:
Run a good query using DSL.
Result:
Run a bad query using DSL. Same deal, just remove the 'eq' level of filter specification. Note that the result is an unfiltered response.
Result:
Expected behavior
Step 5 should raise an equivalent exception to step 3.
System info (please complete the following information):
The text was updated successfully, but these errors were encountered: