Exemple #1
0
def operation_for_entities_fetch(
    selection_set: SelectionSetNode,
    variable_usages: VariableUsages,
    internal_fragments: set[FragmentDefinitionNode],
) -> DocumentNode:
    representations_variable = VariableNode(name=NameNode(value='representations'))

    return DocumentNode(
        definitions=list(
            chain(
                [
                    OperationDefinitionNode(
                        operation=OperationType.QUERY,
                        variable_definitions=list(
                            chain(
                                [
                                    VariableDefinitionNode(
                                        variable=representations_variable,
                                        type=NonNullTypeNode(
                                            type=ListTypeNode(
                                                type=NonNullTypeNode(
                                                    type=NamedTypeNode(name=NameNode(value='_Any'))
                                                )
                                            )
                                        ),
                                    )
                                ],
                                map_fetch_node_to_variable_definitions(variable_usages),
                            )
                        ),
                        selection_set=SelectionSetNode(
                            selections=[
                                FieldNode(
                                    name=NameNode(value='_entities'),
                                    arguments=[
                                        ArgumentNode(
                                            name=NameNode(
                                                value=representations_variable.name.value
                                            ),
                                            value=representations_variable,
                                        )
                                    ],
                                    selection_set=selection_set,
                                )
                            ]
                        ),
                    ),
                ],
                internal_fragments,
            )
        )
    )
def maybe_add_alias(field_node: graphql.FieldNode,
                    arguments: List[graphql.ArgumentNode],
                    seen: Dict[Tuple[str, str], List]) -> None:
    for argument in arguments:
        key = (field_node.name.value, argument.name.value)
        value = argument.value
        if key in seen:
            # Simply add an alias, the values could be the same, so it not technically necessary, but this is safe
            # and simpler, but a bit reduces the possible input variety
            field_node.alias = graphql.NameNode(
                value=f"{field_node.name.value}_{len(seen[key])}")
            seen[key].append(value)
        else:
            seen[key] = [value]
Exemple #3
0
    def __init__(
        self,
        name: str,
        graphql_type: Union[GraphQLObjectType, GraphQLInterfaceType],
        graphql_field: GraphQLField,
    ):
        """Initialize the DSLField.

        .. warning::
            Don't instantiate this class yourself.
            Use attributes of the :class:`DSLType` instead.

        :param name: the name of the field
        :param graphql_type: the GraphQL type definition from the schema
        :param graphql_field: the GraphQL field definition from the schema
        """
        self._type: Union[GraphQLObjectType, GraphQLInterfaceType] = graphql_type
        self.field: GraphQLField = graphql_field
        self.ast_field: FieldNode = FieldNode(
            name=NameNode(value=name), arguments=FrozenList()
        )
        log.debug(f"Creating {self!r}")
Exemple #4
0
 def __init__(self, name, field):
     self.field = field
     self.ast_field = FieldNode(name=NameNode(value=name),
                                arguments=FrozenList())
     self.selection_set = None
Exemple #5
0
from graphql_query_planner.query_plan import (
    FetchNode,
    FlattenNode,
    ParallelNode,
    PlanNode,
    QueryPlan,
    ResponsePath,
    SequenceNode,
    trim_selection_nodes,
)
from graphql_query_planner.shims import GraphQLField
from graphql_query_planner.utilities.graphql_ import get_field_def, get_response_name
from graphql_query_planner.utilities.multi_map import MultiMap
from graphql_query_planner.utilities.predicates import is_not_null_or_undefined

typename_field = FieldNode(name=NameNode(value='__typename'))


@dataclass
class OperationContext:
    schema: GraphQLSchema
    operation: OperationDefinitionNode
    fragments: 'FragmentMap'


FragmentName = str

FragmentMap = dict[FragmentName, FragmentDefinitionNode]


@dataclass