def _get_spreaded_fragment(fragments, spreads):
    spreaded_fragments = []
    for spread in spreads:
        nodes = find_nodes_by_name(fragments, spread["spread"].name.value)
        if nodes:
            spreaded_fragments.append(nodes[0])
    return spreaded_fragments
def _validate_operation(operation, per_operation, per_fragment):
    error_per_var = {}
    defined_vars = get_defined_vars(operation)

    for a_var in get_used_vars(operation, per_operation, per_fragment):
        if not find_nodes_by_name(defined_vars, a_var.name.value):
            error_per_var.setdefault(a_var.name.value, []).append(a_var)

    return error_per_var
    def validate(self, path, fragments, fragment_spreads=None, **__):
        erronous_speads = {}

        if not fragment_spreads:
            fragment_spreads = []

        for spread in fragment_spreads:
            if not find_nodes_by_name(fragments, spread.name.value):
                erronous_speads.setdefault(spread.name.value,
                                           []).append(spread)

        return self._to_errors(erronous_speads, path)
Ejemplo n.º 4
0
    def _validate_fragment(self, fragments, fragment, spreaded):
        for selected in fragment.selection_set.selections:
            if isinstance(selected, FragmentSpreadNode):
                if selected.name.value not in spreaded:
                    spreaded.append(selected.name.value)

                    fragment = find_nodes_by_name(fragments,
                                                  selected.name.value)
                    if not fragment:
                        continue  # Handled by another validator
                    fragment = fragment[0]

                    self._validate_fragment(fragments, fragment, spreaded)
                else:
                    raise CycleException(fragments, self._extensions)
        return
 def _validate_arguments(self, parent_node, schema_definition, path,
                         message_suffix):
     errors = []
     for schema_arg in schema_definition.arguments.values():
         if (isinstance(schema_arg.graphql_type, GraphQLNonNull)
                 and schema_arg.default_value is None
                 and not find_nodes_by_name(parent_node.arguments,
                                            schema_arg.name)):
             errors.append(
                 graphql_error_from_nodes(
                     message=
                     f"Missing mandatory argument < {schema_arg.name} > {message_suffix}",
                     nodes=parent_node,
                     path=path,
                     extensions=self._extensions,
                 ))
     return errors
    def validate(self, path, fragments, fragment_spreads=None, **__):
        errors = []

        if not fragment_spreads:
            fragment_spreads = []

        for fragment in fragments:
            if not find_nodes_by_name(fragment_spreads, fragment.name.value):
                errors.append(
                    graphql_error_from_nodes(
                        message=
                        f"Fragment < {fragment.name.value} > is never used.",
                        nodes=fragment,
                        path=path,
                        extensions=self._extensions,
                    ))

        return errors
    def validate(self, path, fragments, **__):
        errors = []
        already_tested = []

        for fragment in fragments:
            if fragment.name.value in already_tested:
                continue

            with_same_name = find_nodes_by_name(fragments, fragment.name.value)
            if len(with_same_name) > 1:
                already_tested.append(fragment.name.value)
                errors.append(
                    graphql_error_from_nodes(
                        message=
                        f"Can't have multiple fragments named < {fragment.name.value} >.",
                        path=path,
                        nodes=with_same_name,
                        extensions=self._extensions,
                    ))

        return errors
Ejemplo n.º 8
0
    def validate(self, path, operations, **__):
        errors = []
        already_tested = []

        for operation in operations:
            if not operation.name or operation.name.value in already_tested:
                continue

            with_same_name = find_nodes_by_name(operations,
                                                operation.name.value)
            if len(with_same_name) > 1:
                already_tested.append(operation.name.value)
                errors.append(
                    graphql_error_from_nodes(
                        message=
                        f"Can't have multiple operations named < {operation.name.value} >.",
                        path=path,
                        nodes=with_same_name,
                        extensions=self._extensions,
                    ))

        return errors
Ejemplo n.º 9
0
    def validate(self, path, input_fields, **__):
        errors = []
        already_tested = []

        for ifield in input_fields:
            if ifield.name.value in already_tested:
                continue

            with_same_name = find_nodes_by_name(input_fields,
                                                ifield.name.value)
            if len(with_same_name) > 1:
                already_tested.append(ifield.name.value)
                errors.append(
                    graphql_error_from_nodes(
                        message=
                        f"Can't have multiple Input Field named < {ifield.name.value} >.",
                        path=path,
                        nodes=with_same_name,
                        extensions=self._extensions,
                    ))

        return errors
    def validate(self, path, variable_definitions, **__):
        errors = []
        already_tested = []

        variables = [x.variable for x in variable_definitions]

        for variable in variables:
            if variable.name.value in already_tested:
                continue

            with_same_name = find_nodes_by_name(variables, variable.name.value)
            if len(with_same_name) > 1:
                already_tested.append(variable.name.value)
                errors.append(
                    graphql_error_from_nodes(
                        message=
                        f"Can't have multiple variables named < {variable.name.value} >.",
                        path=path,
                        nodes=with_same_name,
                        extensions=self._extensions,
                    ))

        return errors
Ejemplo n.º 11
0
    def validate(self, directives, path, **_):
        errors = []
        already_tested = []

        for directive in directives:
            if directive.name.value in already_tested:
                continue

            with_same_name = find_nodes_by_name(
                directives, directive.name.value
            )
            if len(with_same_name) > 1:
                already_tested.append(directive.name.value)
                errors.append(
                    graphql_error_from_nodes(
                        message=f"Can't have multiple directives named < {directive.name.value} > in the same location.",
                        path=path,
                        nodes=with_same_name,
                        extensions=self._extensions,
                    )
                )

        return errors