Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_graphql_input_object_init():
input_object = GraphQLInputObjectType(
name="Name",
fields=OrderedDict(
[
("test", GraphQLArgument(name="arg", gql_type="Int")),
("another", GraphQLArgument(name="arg", gql_type="String")),
]
),
description="description",
)
assert input_object.name == "Name"
assert input_object._fields == OrderedDict(
[
("test", GraphQLArgument(name="arg", gql_type="Int")),
("another", GraphQLArgument(name="arg", gql_type="String")),
]
def test_graphql_input_object_repr():
input_object = GraphQLInputObjectType(
name="Name",
fields=OrderedDict(
[
("test", GraphQLArgument(name="arg", gql_type="Int")),
("another", GraphQLArgument(name="arg", gql_type="String")),
]
),
description="description",
)
assert (
input_object.__repr__() == "GraphQLInputObjectType(name='Name', "
"fields=OrderedDict(["
"('test', GraphQLArgument(name='arg', gql_type='Int', default_value=None, description=None, directives=None)), "
"('another', GraphQLArgument(name='arg', gql_type='String', default_value=None, description=None, directives=None))"
"]), description='description')"
## Different
assert input_object != GraphQLInputObjectType(
name="Name",
fields=OrderedDict(
[
("another", GraphQLArgument(name="arg", gql_type="String")),
("test", GraphQLArgument(name="arg", gql_type="Int")),
# We reversed the order of arguments
]
),
)
assert input_object != GraphQLInputObjectType(
name="Name", fields=OrderedDict()
)
assert input_object != GraphQLInputObjectType(
name="OtherName",
fields=OrderedDict(
[
("another", GraphQLArgument(name="arg", gql_type="String")),
("test", GraphQLArgument(name="arg", gql_type="Int")),
# We reversed the order of arguments
def test_graphql_input_object_eq():
input_object = GraphQLInputObjectType(
name="Name",
fields=OrderedDict(
[
("test", GraphQLArgument(name="arg", gql_type="Int")),
("another", GraphQLArgument(name="arg", gql_type="String")),
]
),
description="description",
)
## Same
assert input_object == input_object
assert input_object == GraphQLInputObjectType(
name="Name",
fields=OrderedDict(
[
("test", GraphQLArgument(name="arg", gql_type="Int")),
("another", GraphQLArgument(name="arg", gql_type="String")),
]
),
description="description",
)
# Currently we ignore the description in comparing
assert input_object == GraphQLInputObjectType(
name="Name",
fields=OrderedDict(
[
("test", GraphQLArgument(name="arg", gql_type="Int")),
("another", GraphQLArgument(name="arg", gql_type="String")),
GraphQLInputObjectType,
name="UserProfileInput",
fields=OrderedDict(
[
(
"fullName",
call_with_mocked_resolver_factory(
GraphQLArgument,
name="fullName",
gql_type="String",
),
)
]
),
)
],
)
def add_type_definition(self, type_definition: "GraphQLType") -> None:
"""
Adds a GraphQLType to the defined type list.
:param type_definition: GraphQLType to add
:type type_definition: GraphQLType
"""
if type_definition.name in self.type_definitions:
raise RedefinedImplementation(
"new GraphQL type definition `{}` "
"overrides existing type definition `{}`.".format(
type_definition.name,
repr(self.type_definitions.get(type_definition.name)),
)
)
self.type_definitions[type_definition.name] = type_definition
if isinstance(type_definition, GraphQLInputObjectType):
self._input_types.append(type_definition.name)
description = child.value
elif child.type == "IDENT":
name = child.value
elif child.type == "directives":
directives = child.value
elif child.type == "input_fields":
fields = child.value
elif child.type == "discard" or child.type == "INPUT":
pass
else:
raise UnexpectedASTNode(
"Unexpected AST node `{}`, type `{}`".format(
child, child.__class__.__name__
)
)
return GraphQLInputObjectType(
name=name,
fields=fields,
description=description,
schema=self._schema,
directives=directives,
)
def __eq__(self, other: Any) -> bool:
"""
Returns True if `other` instance is identical to `self`.
:param other: object instance to compare to `self`
:type other: Any
:return: whether or not `other` is identical to `self`
:rtype: bool
"""
return self is other or (
isinstance(other, GraphQLInputObjectType)
and self.name == other.name
and self.input_fields == other.input_fields
and self.description == other.description
and self.directives == other.directives
)
type_definition.bake(self)
for directive_definition in self._directive_definitions.values():
directive_definition.bake(self)
for type_definition in self.type_definitions.values():
if isinstance(
type_definition,
(GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType),
):
await type_definition.bake_fields(
self, custom_default_resolver
)
elif isinstance(type_definition, GraphQLEnumType):
await type_definition.bake_enum_values(self)
elif isinstance(type_definition, GraphQLInputObjectType):
await type_definition.bake_input_fields(self)
value.value
if not input_coercer
else input_coercer(value.value, info)
)
except AttributeError:
pass
if value is None:
return None
schema_type = argument_definition.schema.find_type(
reduce_type(argument_definition.gql_type)
)
if (
not isinstance(schema_type, GraphQLInputObjectType)
or argument_definition.is_list_type
):
return value
if (
not isinstance(argument_definition.gql_type, str)
and argument_definition.is_list_type
):
return await asyncio.gather(
*[
coerce_arguments(schema_type.arguments, x, ctx, info)
for x in value
]
)
return await coerce_arguments(schema_type.arguments, value, ctx, info)