Skip to content

DSL not allowing to use a key named "type" #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gdalmau opened this issue Oct 13, 2020 · 0 comments · Fixed by #151
Closed

DSL not allowing to use a key named "type" #150

gdalmau opened this issue Oct 13, 2020 · 0 comments · Fixed by #151
Labels
type: bug An issue or pull request relating to a bug

Comments

@gdalmau
Copy link
Contributor

gdalmau commented Oct 13, 2020

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

gql/gql/dsl.py

Lines 51 to 53 in fce2782

class DSLType(object):
def __init__(self, type_):
self.type = type_

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".
@KingDarBoja KingDarBoja added the type: bug An issue or pull request relating to a bug label Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants