How to use the sgqlc.operation.__init__.SelectionList function in sgqlc

To help you get started, we’ve selected a few sgqlc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
def __to_graphql__(self, indent=0, indent_string='  ',
                       auto_select_depth=DEFAULT_AUTO_SELECT_DEPTH):
        selection = SelectionList.__to_graphql__(
            self, indent, indent_string, auto_select_depth)
        return '... on %s %s' % (self.__type__, selection)
github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
if typ is None:
            typ = global_schema.query_type

        variable_args = OrderedDict()
        for k, v in args.items():
            variable_args['$' + k] = v

        if variable_args and not name:
            name = typ.__name__

        self.__type = typ
        self.__kind = self._get_kind()
        self.__name = name
        self.__args = ArgDict(variable_args)
        self.__args._set_container(typ.__schema__, self)
        self.__selection_list = SelectionList(typ)
github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
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
github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
def __init__(self, alias, field, args):
        self.__alias__ = alias
        self.__field__ = field
        self.__args__ = args
        self.__field_selector = {}
        self.__selection_list = None
        if issubclass(field.type, BaseTypeWithTypename):
            self.__selection_list = SelectionList(field.type)
github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
def __select_all_types(cls, union_type, depth, trail):
        recursive = len(trail) < depth

        q = SelectionList(union_type)
        q.__typename__()
        for t in union_type:
            if recursive and t not in trail:
                sel = q.__as__(t)
                for x in cls.__select_all_fields(t, depth, trail):
                    sel += x
        return q
github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
The newly created selection list is shared for all users
        of the same type in this selection list.
        '''
        try:
            return self.__casts[typ.__name__]
        except KeyError:
            pass

        sl = InlineFragmentSelectionList(typ)
        self.__casts[typ.__name__] = sl
        self['__typename__']()
        return sl


class InlineFragmentSelectionList(SelectionList):
    def __to_graphql__(self, indent=0, indent_string='  ',
                       auto_select_depth=DEFAULT_AUTO_SELECT_DEPTH):
        selection = SelectionList.__to_graphql__(
            self, indent, indent_string, auto_select_depth)
        return '... on %s %s' % (self.__type__, selection)


class Operation:
    '''GraphQL Operation: query or mutation.

    The given type must be one of ``schema.Query`` or
    ``schema.Mutation``, defaults to ``global_schema.Query`` or
    whatever is defined as ``global_schema.query_type``.

    The operation has an internal
    :class:`sgqlc.operation.SelectionList` and will proxy attributes