Skip to content

Commit

Permalink
Default value for required argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Sep 15, 2023
1 parent 338c17f commit 209b5a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
42 changes: 22 additions & 20 deletions gqt/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
}


def is_optional_argument(field_type, default_value):
if field_type['kind'] != 'NON_NULL':
return True
elif default_value is not None:
return True
else:
return False
def is_optional_argument(field_type):
return field_type['kind'] != 'NON_NULL'


def has_default(default_value):
return default_value is not None


class QueryError(Exception):
Expand Down Expand Up @@ -527,7 +526,8 @@ def __init__(self,
self._type = get_type(field_type)['name']
self.type = get_type_string(field_type)
self.description = description
self.is_optional = is_optional_argument(field_type, default_value)
self.is_optional = is_optional_argument(field_type)
self.has_default = has_default(default_value)
self.is_variable = False

if self.is_optional:
Expand All @@ -539,7 +539,7 @@ def __init__(self,
self.types = types
self.value = Value()

if self.is_optional:
if self.is_optional or self.has_default:
self.symbol = '□'
else:
self.symbol = '●'
Expand Down Expand Up @@ -604,7 +604,7 @@ def key(self, key):
def select(self):
if self.state.cursor_at_input_field:
self.key(' ')
elif self.is_optional and not self.is_variable:
elif (self.is_optional or self.has_default) and not self.is_variable:
self.symbol = OPTIONAL_SYMBOLS[self.symbol]

def query(self, variables):
Expand Down Expand Up @@ -698,7 +698,8 @@ def __init__(self,
self.name = name
self.type = get_type_string(field_type)
self.description = description
self.is_optional = is_optional_argument(field_type, default_value)
self.is_optional = is_optional_argument(field_type)
self.has_default = has_default(default_value)
self.is_variable = False

if not self.is_optional:
Expand All @@ -711,7 +712,7 @@ def __init__(self,
self.state = state
self.value = Value()

if self.is_optional:
if self.is_optional or self.has_default:
self.symbol = '□'
else:
self.symbol = '●'
Expand Down Expand Up @@ -787,7 +788,7 @@ def key(self, key):
def select(self):
if self.state.cursor_at_input_field:
self.key(' ')
elif self.is_optional and not self.is_variable:
elif (self.is_optional or self.has_default) and not self.is_variable:
self.symbol = OPTIONAL_SYMBOLS[self.symbol]

def query(self, variables):
Expand Down Expand Up @@ -865,7 +866,8 @@ def __init__(self,
self._type = get_type(field_type)['name']
self.type = get_type_string(field_type)
self.description = description
self.is_optional = is_optional_argument(field_type, default_value)
self.is_optional = is_optional_argument(field_type)
self.has_default = has_default(default_value)
self.is_variable = False
self.state = state
self.types = types
Expand All @@ -879,7 +881,7 @@ def __init__(self,
self.fields = ObjectFields(fields, [], types, state)
self.fields.parent = self

if self.is_optional:
if self.is_optional or self.has_default:
self.symbol = '□'
else:
self.symbol = '●'
Expand Down Expand Up @@ -969,7 +971,7 @@ def key_variable(self):
return True

def select(self):
if self.is_optional and not self.is_variable:
if (self.is_optional or self.has_default) and not self.is_variable:
self.symbol = OPTIONAL_SYMBOLS[self.symbol]

if self.symbol == '■':
Expand Down Expand Up @@ -1180,14 +1182,15 @@ def __init__(self,
self.name = name
self.type = get_type_string(field_type)
self.description = description
self.is_optional = is_optional_argument(field_type, default_value)
self.is_optional = is_optional_argument(field_type)
self.has_default = has_default(default_value)
self.is_variable = False
self.state = state
self.field_type = field_type
self.types = types
self.value = Value()

if self.is_optional:
if self.is_optional or self.has_default:
self.symbol = '□'
else:
self.symbol = '●'
Expand Down Expand Up @@ -1276,7 +1279,7 @@ def item_removed(self, item):
item.next.prev = item.prev

def select(self):
if self.is_optional and not self.is_variable:
if (self.is_optional or self.has_default) and not self.is_variable:
self.symbol = OPTIONAL_SYMBOLS[self.symbol]

if self.symbol == '■':
Expand Down Expand Up @@ -1836,7 +1839,6 @@ def _find_last(self, node):


def load_tree_from_schema(schema):
# print(schema)
types = schema['__schema']['types']
query_type = schema['__schema']['queryType']

Expand Down
2 changes: 1 addition & 1 deletion gqt/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.125.3'
__version__ = '0.125.4'

0 comments on commit 209b5a1

Please sign in to comment.