當前位置: 首頁>>代碼示例>>Python>>正文


Python graphql.graphql_sync方法代碼示例

本文整理匯總了Python中graphql.graphql_sync方法的典型用法代碼示例。如果您正苦於以下問題:Python graphql.graphql_sync方法的具體用法?Python graphql.graphql_sync怎麽用?Python graphql.graphql_sync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在graphql的用法示例。


在下文中一共展示了graphql.graphql_sync方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_executing_mutation_takes_scalar_args_and_returns_scalar_sum

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_executing_mutation_takes_scalar_args_and_returns_scalar_sum():
    type_defs = """
        type Query {
            _: String
        }

        type Mutation {
            sum(a: Int, b: Int): Int
        }
    """

    mutation = MutationType()
    mutation.set_field("sum", lambda *_, a, b: a + b)

    schema = make_executable_schema(type_defs, mutation)

    result = graphql_sync(schema, "mutation { sum(a: 1, b: 2) }")
    assert result.errors is None
    assert result.data == {"sum": 3} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:21,代碼來源:test_mutations.py

示例2: test_same_type_resolver_maps_are_merged_into_executable_schema

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_same_type_resolver_maps_are_merged_into_executable_schema():
    type_defs = """
        type Query {
            hello: String
            test(data: Int): Boolean
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "World!")

    extending_query = QueryType()

    @extending_query.field("test")
    def resolve_test(*_, data):  # pylint: disable=unused-variable
        assert data == 4
        return True

    schema = make_executable_schema(type_defs, [query, extending_query])

    result = graphql_sync(schema, "{ hello test(data: 4) }")
    assert result.errors is None
    assert result.data == {"hello": "World!", "test": True} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:25,代碼來源:test_modularization.py

示例3: test_different_types_resolver_maps_are_merged_into_executable_schema

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_different_types_resolver_maps_are_merged_into_executable_schema():
    type_defs = """
        type Query {
            user: User
        }

        type User {
            username: String
        }
    """

    query = QueryType()
    query.set_field("user", lambda *_: Mock(first_name="Joe"))

    user = ObjectType("User")
    user.set_alias("username", "first_name")

    schema = make_executable_schema(type_defs, [query, user])

    result = graphql_sync(schema, "{ user { username } }")
    assert result.errors is None
    assert result.data == {"user": {"username": "Joe"}} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:24,代碼來源:test_modularization.py

示例4: test_multiple_bindables_can_be_passed_as_separate_args

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_multiple_bindables_can_be_passed_as_separate_args():
    type_defs = """
        type Query {
            user: User
        }

        type User {
            username: String
        }
    """

    query = QueryType()
    query.set_field("user", lambda *_: Mock(first_name="Joe"))

    user = ObjectType("User")
    user.set_alias("username", "first_name")

    schema = make_executable_schema(type_defs, query, user)

    result = graphql_sync(schema, "{ user { username } }")
    assert result.errors is None
    assert result.data == {"user": {"username": "Joe"}} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:24,代碼來源:test_modularization.py

示例5: test_reference_resolver_can_be_set_using_decorator

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_reference_resolver_can_be_set_using_decorator(schema):
    obj = FederatedObjectType("Product")
    obj.reference_resolver()(lambda *_: {"name": "Malbec"})
    obj.bind_to_schema(schema)

    result = graphql_sync(
        schema,
        """
            query GetEntities($representations: [_Any!]!) {
                _entities(representations: $representations) {
                    ... on Product {
                        name
                    }
                }
            }
        """,
        variable_values={"representations": [{"__typename": "Product", "upc": 1}]},
    )

    assert result.errors is None
    assert result.data["_entities"] == [{"name": "Malbec"}] 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:23,代碼來源:test_objects.py

示例6: test_reference_resolver_can_be_set_using_setter

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_reference_resolver_can_be_set_using_setter(schema):
    obj = FederatedObjectType("Product")
    obj.reference_resolver(lambda *_: {"name": "Malbec"})
    obj.bind_to_schema(schema)

    result = graphql_sync(
        schema,
        """
            query GetEntities($representations: [_Any!]!) {
                _entities(representations: $representations) {
                    ... on Product {
                        name
                    }
                }
            }
        """,
        variable_values={"representations": [{"__typename": "Product", "upc": 1}]},
    )

    assert result.errors is None
    assert result.data["_entities"] == [{"name": "Malbec"}] 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:23,代碼來源:test_objects.py

示例7: test_multiple_field_definition_directives_replace_field_resolver_with_chainable_resolvers

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_multiple_field_definition_directives_replace_field_resolver_with_chainable_resolvers():
    type_defs = """
        directive @upper on FIELD_DEFINITION
        directive @reverse on FIELD_DEFINITION

        type Query {
            hello: String @upper @reverse
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "hello world")

    schema = make_executable_schema(
        type_defs,
        [query],
        directives={"upper": UpperDirective, "reverse": ReverseDirective},
    )

    result = graphql_sync(schema, "{ hello }")
    assert result.errors is None
    assert result.data == {"hello": "DLROW OLLEH"} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:24,代碼來源:test_directives.py

示例8: test_directive_can_have_optional_argument

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_directive_can_have_optional_argument():
    type_defs = """
        directive @test(arg: String) on FIELD_DEFINITION

        type Query {
            hello: String @test
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "hello world")

    schema = make_executable_schema(
        type_defs, [query], directives={"test": ReturnValueDirective}
    )

    result = graphql_sync(schema, "{ hello }")
    assert result.errors is None
    assert result.data == {"hello": None} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:21,代碼來源:test_directives.py

示例9: test_directive_can_have_required_argument

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_directive_can_have_required_argument():
    type_defs = """
        directive @test(arg: String) on FIELD_DEFINITION

        type Query {
            hello: String @test(arg: "OK!")
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "hello world")

    schema = make_executable_schema(
        type_defs, [query], directives={"test": ReturnValueDirective}
    )

    result = graphql_sync(schema, "{ hello }")
    assert result.errors is None
    assert result.data == {"hello": "OK!"} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:21,代碼來源:test_directives.py

示例10: test_default_resolver_resolves_value_from_dict_item

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_default_resolver_resolves_value_from_dict_item():
    type_defs = """
        type Query {
            test: Custom
        }

        type Custom {
            node: String
        }
    """

    query = QueryType()
    query.set_field("test", lambda *_: {"node": "custom"})

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test { node } }")
    assert result.errors is None
    assert result.data == {"test": {"node": "custom"}} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:21,代碼來源:test_queries.py

示例11: test_default_resolver_resolves_value_from_object_attr

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_default_resolver_resolves_value_from_object_attr():
    type_defs = """
        type Query {
            test: Custom
        }

        type Custom {
            node: String
        }
    """

    query = QueryType()
    query.set_field("test", lambda *_: Mock(node="custom"))

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test { node } }")
    assert result.errors is None
    assert result.data == {"test": {"node": "custom"}} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:21,代碼來源:test_queries.py

示例12: test_custom_and_default_resolvers_are_combined_to_resolve_custom_type_fields

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_custom_and_default_resolvers_are_combined_to_resolve_custom_type_fields():
    type_defs = """
        type Query {
            test: Custom
        }

        type Custom {
            node: String
            default: String
        }
    """

    query = QueryType()
    query.set_field("test", lambda *_: {"node": "custom", "default": "ok"})

    custom = ObjectType("Custom")
    custom.set_field("node", lambda *_: "deep")

    schema = make_executable_schema(type_defs, [query, custom])

    result = graphql_sync(schema, "{ test { node default } }")
    assert result.errors is None
    assert result.data == {"test": {"node": "deep", "default": "ok"}} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:25,代碼來源:test_queries.py

示例13: test_custom_resolver_is_called_with_arguments_passed_with_query

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_custom_resolver_is_called_with_arguments_passed_with_query():
    type_defs = """
        type Query {
            test(returnValue: Int!): Int
        }
    """

    query = QueryType()

    @query.field("test")
    def resolve_test(*_, returnValue):  # pylint: disable=unused-variable
        assert returnValue == 4
        return "42"

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test(returnValue: 4) }")
    assert result.errors is None
    assert result.data == {"test": 42} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:21,代碼來源:test_queries.py

示例14: test_custom_resolver_is_called_with_input_type_value_as_dict

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_custom_resolver_is_called_with_input_type_value_as_dict():
    type_defs = """
        type Query {
            test(data: TestInput): Int
        }

        input TestInput {
            value: Int
        }
    """

    query = QueryType()

    @query.field("test")
    def resolve_test(*_, data):  # pylint: disable=unused-variable
        assert data == {"value": 4}
        return "42"

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test(data: { value: 4 }) }")
    assert result.errors is None
    assert result.data == {"test": 42} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:25,代碼來源:test_queries.py

示例15: test_executing_mutation_takes_scalar_arg_and_returns_type

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import graphql_sync [as 別名]
def test_executing_mutation_takes_scalar_arg_and_returns_type():
    type_defs = """
        type Query {
            _: String
        }

        type Staff {
            name: String
        }

        type Mutation {
            addStaff(name: String): Staff
        }
    """

    mutation = MutationType()

    @mutation.field("addStaff")
    def resolve_add_staff(*_, name):  # pylint: disable=unused-variable
        assert name == "Bob"
        return {"name": name}

    schema = make_executable_schema(type_defs, mutation)

    result = graphql_sync(schema, 'mutation { addStaff(name: "Bob") { name } }')
    assert result.errors is None
    assert result.data == {"addStaff": {"name": "Bob"}} 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:29,代碼來源:test_mutations.py


注:本文中的graphql.graphql_sync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。