Skip to content

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

Closed
@gdalmau

Description

@gdalmau

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugAn issue or pull request relating to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions