How to use the sgqlc.operation.__init__.Selection 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 __iadd__(self, selection):
        assert isinstance(selection, Selection)
        self.__selections.append(selection)
        return self
github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
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
github profusion / sgqlc / sgqlc / operation / __init__.py View on Github external
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)
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