DSL does not provide expected argument validation
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu với dsl.dsl_gql và so sánh hành vi của nó với gql.gql bằng bản tái hiện API countries trong Issue này. Theo dõi cách các đối số của truy vấn DSL được xử lý và xác minh rằng bộ lọc không đúng định dạng ở bước 5 tạo ra một GraphQLError tương đương thay vì trả về các kết quả chưa được lọc.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 1.7k
- Fork
- 195
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của graphql-python/gql
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
graphql-python/gql#613 · 2 bình luận ·
-
type: feature
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
graphql-python/gql#434 ·
-
type: feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
graphql-python/gql#373 · 1 reaction ·
-
type: feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
graphql-python/gql#316 · 5 bình luận · 3 reaction ·
Tất cả issue của graphql-python/gql
Issue tương tự
-
essnmx good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
[Feature] 奇物选择添加优先级 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
syfoud/Simulated_Scepter#174 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Giskard-AI/giskard-oss#2840 · 1 bình luận ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Đang mởarea: repo bug perceived difficulty: 2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
yeti-platform/yeti#1380 ·