Closed
Description
Description
When trying to obtain a key named type
from a specific GraphQL type, it raises an error.
The problem could be because the type
attribute is already assigned to DSLType
in
Lines 51 to 53 in fce2782
Steps to reproduce
- Have a
.graphql
file with the schema. For example:
type Query {
my_restaurant: Restaurant
}
enum RestaurantType {
italian
indian
fast_food
}
type Restaurant {
type: RestaurantType!
address: String
name: String
}
- Create a query to fetch
Restaurant.type
from schema import schema
from gql import Client
from gql.dsl import DSLSchema
client = Client(schema=schema)
ds = DSLSchema(client)
query = ds.Query.my_restaurant.select(
ds.Restaurant.type
)
- It raises the following error:
Error
Traceback (most recent call last):
File "/opt/project/src/apps/graphql/tests/test_graphql.py", line 80, in test_restaurant
query = ds.Query.my_restaurant.select(
File "/usr/local/lib/python3.8/site-packages/gql/dsl.py", line 91, in select
selections=FrozenList(added_selections)
File "/usr/local/lib/python3.8/site-packages/gql/dsl.py", line 73, in selections
yield selection_field(_field).ast
File "/usr/local/lib/python3.8/site-packages/gql/dsl.py", line 127, in selection_field
raise TypeError(f'Received incompatible query field: "{field}".')
TypeError: Received incompatible query field: "Restaurant".