DSL does not provide expected argument validation
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 42/100
Rechercherichtung
Beginne mit dsl.dsl_gql und vergleiche sein Verhalten anhand der Reproduktion der countries API in diesem Issue mit gql.gql. Verfolge, wie die Argumente der DSL-Abfrage verarbeitet werden, und überprüfe, dass der fehlerhafte Filter in Schritt 5 einen äquivalenten GraphQLError auslöst, anstatt ungefilterte Ergebnisse zurückzugeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
- 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.
import json import gql from gql.transport.requests import RequestsHTTPTransport as Transport from gql import dsl url = "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) -
Run a good query using strings.
good_query_str = gql.gql( """ query { continents (filter:{code:{eq:"AN"}}) { code name } } """ ) result = client.execute(good_query_str) print(json.dumps(result, indent=2))Result:
{ "continents": [ { "code": "AN", "name": "Antarctica" } ] } -
Run a bad query using strings. The only change here is using
'AN'directly as an argument tocode, instead of providing theeqdirective.bad_query_str = gql.gql( """ query { continents (filter:{code:"AN"}) { code name } } """ ) result = client.execute(bad_query_str) print(json.dumps(result, indent=2))Result:
GraphQLError: Expected value of type 'StringQueryOperatorInput', found "AN". GraphQL request:3:34 2 | query { 3 | continents (filter:{code:"AN"}) { | ^ 4 | code -
Run a good query using DSL.
good_query_dsl = dsl.dsl_gql( dsl.DSLQuery( ds.Query.continents( filter={ 'code': {'eq': 'AN'} } ).select( ds.Continent.code, ds.Continent.name, ) ) ) result = client.execute(good_query_dsl) print(json.dumps(result, indent=2))Result:
{ "continents": [ { "code": "AN", "name": "Antarctica" } ] } -
Run a bad query using DSL. Same deal, just remove the 'eq' level of filter specification. Note that the result is an unfiltered response.
bad_query_dsl = dsl.dsl_gql( dsl.DSLQuery( ds.Query.continents( filter={ 'code': 'AN' } ).select( ds.Continent.code, ds.Continent.name, ) ) ) result = client.execute(bad_query_dsl) print(json.dumps(result, indent=2))Result:
{ "continents": [ { "code": "AF", "name": "Africa" }, { "code": "AN", "name": "Antarctica" }, { "code": "AS", "name": "Asia" }, { "code": "EU", "name": "Europe" }, { "code": "NA", "name": "North America" }, { "code": "OC", "name": "Oceania" }, { "code": "SA", "name": "South America" } ] }
Expected behavior
Step 5 should raise an equivalent exception to step 3.
System info (please complete the following information):
- OS: Wins 10
- Python version: 3.9.12
- gql version: 3.4.0
- graphql-core version: 3.2.1
- Vorherrschende Sprache
- Python
- Sterne
- 1.7k
- Forks
- 197
- Ø Merge
- 12 Min.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus graphql-python/gql
-
RequestsHTTPTransport does not set headers on session like AIOHTTPTransport doesEvtl. vergeben @shtrom hat das vor 46 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
graphql-python/gql#613 · 2 Kommentare ·
-
type: feature
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 42/100
graphql-python/gql#434 ·
-
type: feature
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
graphql-python/gql#373 · 1 Reaktion ·
-
type: feature
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
graphql-python/gql#316 · 5 Kommentare · 3 Reaktionen ·
Alle Issues in graphql-python/gql
Ähnliche Issues
-
python-version
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug javascript P2-medium python release:v3.1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
adrirubio/claude-deck#546 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: desktop area: website priority: P2 type: feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
appandflow/stim#3411 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
baptistehamon/lsapy#185 ·
Maintainer antworten meist innerhalb von 1 Tag