本文整理汇总了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}
示例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}
示例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"}}
示例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"}}
示例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"}]
示例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"}]
示例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"}
示例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}
示例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!"}
示例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"}}
示例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"}}
示例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"}}
示例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}
示例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}
示例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"}}