Ejemplo n.º 1
0
def validate_sensitive_fields_map(sensitive_fields: SensitiveFieldsMap,
                                  schema: GraphQLSchema):
    type_map = schema.get_type_map()
    for type_name, type_fields in sensitive_fields.items():
        if type_name not in type_map:
            raise GraphQLError(
                "The query anonymization could not be performed "
                f"because a type {type_name} that is not defined "
                "is specified as sensitive.")
        if not isinstance(type_map[type_name], GraphQLObjectType):
            raise GraphQLError(
                "The query anonymization could not be performed because a type "
                f"{type_name} specified as sensitive is not an object type.")
        for field_name in type_fields:
            graphql_type = cast(GraphQLObjectType, type_map[type_name])
            if field_name not in graphql_type.fields:
                raise GraphQLError(
                    "The query anonymization could not be performed because a field "
                    f"{field_name} specified as sensitive is not "
                    f"defined by the {type_name} type.")
Ejemplo n.º 2
0
def validate_cost_map(cost_map: Dict[str, Dict[str, Any]], schema: GraphQLSchema):
    type_map = schema.get_type_map()
    for type_name, type_fields in cost_map.items():
        if type_name not in type_map:
            raise GraphQLError(
                "The query cost could not be calculated because cost map specifies "
                f"a type {type_name} that is not defined by the schema."
            )

        if not isinstance(type_map[type_name], GraphQLObjectType):
            raise GraphQLError(
                "The query cost could not be calculated because cost map specifies "
                f"a type {type_name} that is defined by the schema, but is not an "
                "object type."
            )

        for field_name in type_fields:
            graphql_type = cast(GraphQLObjectType, type_map[type_name])
            if field_name not in graphql_type.fields:
                raise GraphQLError(
                    "The query cost could not be calculated because cost map contains "
                    f"a field {field_name} not defined by the {type_name} type."
                )
Ejemplo n.º 3
0
def add_resolve_functions_to_schema(schema: GraphQLSchema, resolvers: dict):
    for type_name, type_object in schema.get_type_map().items():
        if isinstance(type_object, GraphQLObjectType):
            add_resolve_functions_to_object(type_name, type_object, resolvers)
        if isinstance(type_object, GraphQLScalarType):
            add_resolve_function_to_scalar(type_name, type_object, resolvers)