Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def ttftt_engine():
@Resolver("Mutation.mutateFloat", schema_name="issue270")
async def resolver_test(pr, args, ctx, info, **kwargs):
return {"bingo": f"{args['aFloat']}"}
return await create_engine(
sdl="""
type Payload {
clientMutationId: String,
bingo: String
}
type Mutation {
mutateFloat(aFloat: Float): Payload
}
type Query {
bob: String
}
""",
schema_name="issue270",
def parse_literal(ast: "Node") -> Union[str, "UNDEFINED_VALUE"]:
return (
ast.value.capitalize()
if isinstance(ast, StringValueNode)
else UNDEFINED_VALUE
)
@Resolver("Query.person", schema_name="test_issue185")
async def the_query_person_resolver(_parents, args, _ctx, _info):
return args
@Resolver("Query.complexPerson", schema_name="test_issue185")
async def the_query_complexPerson_resolver(_parents, args, _ctx, _info):
return args["details"]
return await create_engine(sdl=_SDL, schema_name="test_issue185")
async def test_issue140_except():
with pytest.raises(ImportError):
await create_engine("""a""", modules=["unkn.nown.modules"])
):
raise ValueError("[ERROR] on_post_input_coercion")
async def resolve_query_input_object_field(parent, args, ctx, info):
if "param" not in args:
return "SUCCESS"
if args["param"] is None:
return "SUCCESS-None"
if not args["param"] and isinstance(args["param"], dict):
return "SUCCESS-{}"
return f"SUCCESS-{args['param']}"
return await create_engine(
_SDL, schema_name="test_coercer_input_object_field_error"
)
async def test_union_type_resolvers_field_resolver(
result, field_type_resolver, expected, random_schema_name
):
@Resolver(
"Query.mixed",
type_resolver=field_type_resolver,
schema_name=random_schema_name,
)
async def resolve_query_mixed(parent, args, ctx, info):
return result
engine = await create_engine(_SDL, schema_name=random_schema_name)
assert await engine.execute(_UNION_QUERY) == expected
async def test_engine_execute_custom_error_coercer(clean_registry):
async def custom_error_coercer(exception, error):
error["message"] = error["message"] + "Custom"
return error
e = await create_engine(
"type Query { a: String }", error_coercer=custom_error_coercer
)
assert await e.execute("query { unknownNode1 unknownNode2 }") == {
"data": None,
"errors": [
{
"message": "field `Query.unknownNode1` was not found in GraphQL schema.Custom",
"path": ["unknownNode1"],
"locations": [{"column": 9, "line": 1}],
},
{
"message": "field `Query.unknownNode2` was not found in GraphQL schema.Custom",
"path": ["unknownNode2"],
"locations": [{"column": 22, "line": 1}],
},
async def ttftt_engine():
return await create_engine(sdl=_SDL, schema_name="test_issue143")
ctx: Optional[Any],
info: "ResolveInfo",
):
result = await next_resolver(parent, args, ctx, info)
return result.upper() if isinstance(result, str) else result
@Resolver("Query.person", schema_name="test_directives_arguments")
async def resolve_query_person(parent, args, ctx, info):
return {
"id": args["id"],
"name": "Person.name",
"nickname": "Person.nickname",
"hobby": "Sport",
}
return await create_engine(_SDL, schema_name="test_directives_arguments")
"""An amazing object"""
type MyType {
"""MyType.firstField"""
firstField: String @deprecated(reason: "Why not?")
"""MyType.secondField"""
secondField: String
}
type Query {
uselessField: [MyEnum]
aField: MyType
}
'''
engine = await create_engine(sdl, schema_name=random_schema_name)
result = await engine.execute(
"""
{{
__type(name: "{}") {{
name
kind
description
fields(includeDeprecated: {}) {{
name
description
isDeprecated
deprecationReason
}}
}}
}}
class CustomException(TartifletteError):
def __init__(self, code, message):
super().__init__(message)
self.code = code
self.extensions = {"code": code}
@Resolver("Query.test")
@Resolver("Obj.deep")
async def resolver_x(*_args, **_kwargs):
return {}
@Resolver("Nested.lastUpdate")
async def func_field_resolver(*args, **kwargs):
raise CustomException("my_error", "There is an error")
ttftt = await create_engine(schema_sdl)
result = await ttftt.execute(
"""
query Test{
test {
deep {
lastUpdate
}
}
}
""",
operation_name="Test",
)
assert {
"data": {"test": {"deep": {"lastUpdate": None}}},