Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __iadd__(self, selection):
assert isinstance(selection, Selection)
self.__selections.append(selection)
return self
To provide an alias, use ``__alias__`` keyword argument.
'''
alias = None
if '__alias__' in args:
alias = args.pop('__alias__')
s = self.__selections.get(alias)
if s is not None:
if not args:
return s
raise ValueError(
('%s already have a selection %s. '
'Maybe use __alias__ as param?') % (self.__field__, s))
s = self.__selections[alias] = Selection(alias, self.__field__, args)
self.__parent__ += s
return s
def __dir__(self):
original_dir = super(Selection, self).__dir__()
t = self.__field__.type
if not issubclass(t, ContainerType):
return original_dir
fields = [f.name for f in t]
return sorted(original_dir + fields)
def __select_all_fields(cls, container_type, depth, trail):
recursive = len(trail) < depth
q = SelectionList(container_type)
for f in container_type:
sel = Selection(None, f, {})
if issubclass(f.type, BaseTypeWithTypename):
if recursive and f.type not in trail:
# change the locally created selection list to the
# auto-selected one. This must be explicit here so
# it doesn't affect __to_graphql__(), that one must not
# affect the actual selection it's operating on!
sel.__selection_list = \
sel.__get_all_fields_selection_list(depth, trail)
else:
sel = None
if sel:
q += sel
return q