def throws_when_subscription_type_not_defined_in_schema():
     test_schema = GraphQLSchema()
     doc = parse("subscription { field }")
     operation_node = get_operation_node(doc)
     with raises(GraphQLError) as exc_info:
         get_operation_root_type(test_schema, operation_node)
     assert exc_info.value.message == "Schema is not configured for subscriptions."
 def throws_when_query_type_not_defined_in_schema():
     test_schema = GraphQLSchema()
     doc = parse("query { field }")
     operation_node = get_operation_node(doc)
     with raises(GraphQLError) as exc_info:
         get_operation_root_type(test_schema, operation_node)
     assert exc_info.value.message == (
         "Schema does not define the required query root type.")
 def throws_when_subscription_type_not_defined_in_schema():
     test_schema = GraphQLSchema()
     doc = parse("subscription { field }")
     operation = doc.definitions[0]
     assert isinstance(operation, OperationDefinitionNode)
     with raises(GraphQLError) as exc_info:
         get_operation_root_type(test_schema, operation)
     assert exc_info.value.message == "Schema is not configured for subscriptions."
 def throws_when_operation_not_a_valid_operation_kind():
     test_schema = GraphQLSchema()
     doc = parse("{ field }")
     operation_node = get_operation_node(doc)
     operation_node.operation = "non_existent_operation"  # type: ignore
     with raises(GraphQLError) as exc_info:
         get_operation_root_type(test_schema, operation_node)
     assert exc_info.value.message == (
         "Can only have query, mutation and subscription operations.")
 def throws_when_query_type_not_defined_in_schema():
     test_schema = GraphQLSchema()
     doc = parse("query { field }")
     operation = doc.definitions[0]
     assert isinstance(operation, OperationDefinitionNode)
     with raises(GraphQLError) as exc_info:
         get_operation_root_type(test_schema, operation)
     assert exc_info.value.message == (
         "Schema does not define the required query root type.")
 def throws_when_operation_not_a_valid_operation_kind():
     test_schema = GraphQLSchema()
     doc = parse("{ field }")
     operation = doc.definitions[0]
     assert isinstance(operation, OperationDefinitionNode)
     operation.operation = "non_existent_operation"
     with raises(GraphQLError) as exc_info:
         get_operation_root_type(test_schema, operation)
     assert exc_info.value.message == (
         "Can only have query, mutation and subscription operations.")
Exemple #7
0
def create_resolve_info(schema,
                        request_string,
                        variables=None,
                        return_type=None):
    exe_context = create_execution_context(schema, request_string, variables)
    parent_type = get_operation_root_type(schema, exe_context.operation)
    field_asts = get_field_asts_from_execution_context(exe_context)

    field_ast = field_asts[0]
    field_name = field_ast.name.value

    if return_type is None:
        field_def = get_field_def(schema, parent_type, field_name)
        if not field_def:
            return Undefined
        return_type = field_def.type

    # The resolve function's optional third argument is a context value that
    # is provided to every resolve function within an execution. It is commonly
    # used to represent an authenticated user, or request-specific caches.
    return GraphQLResolveInfo(
        field_name,
        field_asts,
        return_type,
        parent_type,
        Path(None, 0, None),
        schema,
        exe_context.fragments,
        exe_context.root_value,
        exe_context.operation,
        exe_context.variable_values,
        exe_context.context_value,
        exe_context.is_awaitable,
    )
 def gets_a_subscription_type_for_an_operation_definition_node():
     test_schema = GraphQLSchema(subscription=subscription_type)
     doc = parse("subscription { field }")
     operation = doc.definitions[0]
     assert isinstance(operation, OperationDefinitionNode)
     assert get_operation_root_type(test_schema,
                                    operation) is subscription_type
 def gets_a_type_for_operation_definition_nodes():
     test_schema = GraphQLSchema(query_type, mutation_type,
                                 subscription_type)
     doc = parse("schema { query: FooQuery"
                 " mutation: FooMutation subscription: FooSubscription }")
     schema = doc.definitions[0]
     assert isinstance(schema, SchemaDefinitionNode)
     operations = schema.operation_types
     operation = operations[0]
     assert isinstance(operation, OperationTypeDefinitionNode)
     assert get_operation_root_type(test_schema, operation) is query_type
     operation = operations[1]
     assert isinstance(operation, OperationTypeDefinitionNode)
     assert get_operation_root_type(test_schema, operation) is mutation_type
     operation = operations[2]
     assert isinstance(operation, OperationTypeDefinitionNode)
     assert get_operation_root_type(test_schema,
                                    operation) is subscription_type
    def gets_a_type_for_operation_definition_nodes():
        test_schema = GraphQLSchema(query_type, mutation_type,
                                    subscription_type)
        doc = parse("""
            schema {
              query: FooQuery
              mutation: FooMutation
              subscription: FooSubscription
            }
            """)

        schema_node = doc.definitions[0]
        assert isinstance(schema_node, SchemaDefinitionNode)
        query_node, mutation_node, subscription_node = schema_node.operation_types
        assert isinstance(query_node, OperationTypeDefinitionNode)
        assert get_operation_root_type(test_schema, query_node) is query_type
        assert isinstance(mutation_node, OperationTypeDefinitionNode)
        assert get_operation_root_type(test_schema,
                                       mutation_node) is mutation_type
        assert isinstance(subscription_node, OperationTypeDefinitionNode)
        assert (get_operation_root_type(test_schema, subscription_node) is
                subscription_type)
 def gets_a_subscription_type_for_an_operation_definition_node():
     test_schema = GraphQLSchema(subscription=subscription_type)
     doc = parse("subscription { field }")
     operation_node = get_operation_node(doc)
     assert get_operation_root_type(test_schema,
                                    operation_node) is subscription_type
 def gets_a_mutation_type_for_an_operation_definition_node():
     test_schema = GraphQLSchema(mutation=mutation_type)
     doc = parse("mutation { field }")
     operation_node = get_operation_node(doc)
     assert get_operation_root_type(test_schema,
                                    operation_node) is mutation_type
 def gets_a_query_type_for_a_named_operation_definition_node():
     test_schema = GraphQLSchema(query_type)
     doc = parse("query Q { field }")
     operation_node = get_operation_node(doc)
     assert get_operation_root_type(test_schema,
                                    operation_node) is query_type
 def gets_a_query_type_for_a_named_operation_definition_node():
     test_schema = GraphQLSchema(query_type)
     doc = parse("query Q { field }")
     operation = doc.definitions[0]
     assert isinstance(operation, OperationDefinitionNode)
     assert get_operation_root_type(test_schema, operation) is query_type
Exemple #15
0
 def gets_a_mutation_type_for_an_operation_definition_node():
     test_schema = GraphQLSchema(mutation=mutation_type)
     doc = parse('mutation { field }')
     operation = doc.definitions[0]
     assert isinstance(operation, OperationDefinitionNode)
     assert get_operation_root_type(test_schema, operation) is mutation_type