Skip to content

DSL: Allow to use GraphQL keys named type #151

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

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gql/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def execute(self, document):

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

def __getattr__(self, name):
formatted_name, field_def = self.get_field(name)
Expand All @@ -59,13 +59,13 @@ def __getattr__(self, name):
def get_field(self, name):
camel_cased_name = to_camel_case(name)

if name in self.type.fields:
return name, self.type.fields[name]
if name in self._type.fields:
return name, self._type.fields[name]

if camel_cased_name in self.type.fields:
return camel_cased_name, self.type.fields[camel_cased_name]
if camel_cased_name in self._type.fields:
return camel_cased_name, self._type.fields[camel_cased_name]

raise KeyError(f"Field {name} does not exist in type {self.type.name}.")
raise KeyError(f"Field {name} does not exist in type {self._type.name}.")


def selections(*fields):
Expand Down