Example #1
0
    def _fragment_spread(self, ctx: InternalVisitorContext,
                         element: _VisitorElement) -> None:
        _ctx = self._internal_ctx
        self._internal_ctx = ctx

        self._used_fragments.add(element.name)
        try:
            cfd = self._fragments[element.name]
        except KeyError:
            self._add_exception(
                UndefinedFragment(
                    "Undefined fragment < %s >." % element.name,
                    locations=[element.get_location()],
                ))
            return

        depth = self._internal_ctx.depth
        self._internal_ctx.type_condition = cfd.type_condition

        self._in_fragment_spread_context = True
        for saved_callback in cfd.callbacks:
            saved_callback(  # Simulate calling a the right place.
                type_cond_depth=depth)
        self._in_fragment_spread_context = False

        self._internal_ctx.type_condition = None
        self._internal_ctx = _ctx
Example #2
0
    def _fragment_spread(
        self,
        ctx: InternalVisitorContext,
        element: _VisitorElement,
        directives: [Dict[str, Any]],
    ) -> None:
        _ctx = self._internal_ctx
        self._internal_ctx = ctx

        self._used_fragments.add(element.name)
        try:
            cfd = self._fragments[element.name]
        except KeyError:
            self._add_exception(
                UndefinedFragment(
                    "Undefined fragment < %s >." % element.name,
                    locations=[element.get_location()],
                )
            )
            return

        depth = self._internal_ctx.depth
        self._internal_ctx.type_condition = cfd.type_condition

        self._in_fragment_spread_context = True
        kwargs = {"type_cond_depth": depth}
        for saved_callback in cfd.callbacks:
            kwargs["directives"] = None
            if depth == self._internal_ctx.depth:
                kwargs["directives"] = directives

            saved_callback(**kwargs)  # Simulate calling a the right place.

        self._in_fragment_spread_context = False

        self._internal_ctx.type_condition = None
        self._internal_ctx = _ctx