DSL does not provide expected argument validation
还没有人认领这个 Issue。
评估
调研方向
从 dsl.dsl_gql 开始,使用此 Issue 中的 countries API 复现来比较它与 gql.gql 的行为。跟踪 DSL 查询参数的处理方式,并验证第 5 步中的格式错误过滤器会引发等效的 GraphQLError,而不是返回未过滤的结果。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 195
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql-python/gql 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
graphql-python/gql#613 · 2 条评论 ·
-
type: feature
难度 3/5 1-2 天 新手友好度 42/100
graphql-python/gql#434 ·
-
type: feature
难度 5/5 一周以上 新手友好度 35/100
graphql-python/gql#373 · 1 个 reaction ·
-
type: feature
难度 5/5 一周以上 新手友好度 25/100
graphql-python/gql#316 · 5 条评论 · 3 个 reaction ·
查看 graphql-python/gql 的全部 Issue
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·