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_resolver_factory__resolver_executor_update_prop_contains_not_null(
_resolver_executor_mock
):
from tartiflette.types.field import GraphQLField
from tartiflette.types.non_null import GraphQLNonNull
from tartiflette.types.list import GraphQLList
_resolver_executor_mock._schema_field = GraphQLField("A", gql_type="F")
assert not _resolver_executor_mock.contains_not_null
_resolver_executor_mock._schema_field = GraphQLField(
"A", gql_type=GraphQLNonNull(gql_type="F")
)
assert _resolver_executor_mock.contains_not_null
_resolver_executor_mock._schema_field = GraphQLField(
"A", gql_type=GraphQLList(gql_type=GraphQLNonNull(gql_type="F"))
)
assert _resolver_executor_mock.contains_not_null
_resolver_executor_mock._schema_field = GraphQLField(
"A", gql_type=GraphQLList(gql_type="F")
)
assert not _resolver_executor_mock.contains_not_null
def test_graphql_non_null_eq():
non_null = GraphQLNonNull(gql_type="Name", description="description")
## Same
assert non_null == non_null
assert non_null == GraphQLNonNull(
gql_type="Name", description="description"
)
# Currently we ignore the description in comparing
assert non_null == GraphQLNonNull(gql_type="Name")
## Different
assert non_null != GraphQLNonNull(gql_type="OtherName")
def test_graphql_non_null_repr():
non_null = GraphQLNonNull(gql_type="Name", description="description")
assert (
non_null.__repr__() == "GraphQLNonNull(gql_type='Name', "
"description='description')"
)
assert non_null == eval(repr(non_null))
from tartiflette.utils.coercer import _get_type_coercers
from tartiflette.types.list import GraphQLList
from tartiflette.types.non_null import GraphQLNonNull
from tartiflette.utils.coercer import _list_coercer, _not_null_coercer
assert _get_type_coercers("aType") == []
assert _get_type_coercers(None) == []
assert _get_type_coercers(GraphQLList(gql_type="aType")) == [_list_coercer]
assert _get_type_coercers(GraphQLNonNull(gql_type="aType")) == [
_not_null_coercer
]
assert _get_type_coercers(
GraphQLList(gql_type=GraphQLNonNull(gql_type="aType"))
) == [_list_coercer, _not_null_coercer]
assert _get_type_coercers(
GraphQLNonNull(
gql_type=GraphQLList(gql_type=GraphQLNonNull(gql_type="aType"))
)
) == [_not_null_coercer, _list_coercer, _not_null_coercer]
GraphQLNonNull(
gql_type=GraphQLList(
gql_type=GraphQLNonNull(gql_type="LeafType")
)
),
"LeafType",
),
],
)
def test_reduce_type(gql_type, expected):
reduced_gql_type = reduce_type(gql_type)
assert reduced_gql_type == expected
def _inject_introspection_fields(self) -> None:
"""
Injects introspection fields to the query type and to defined object
and union types.
"""
query_type = self.type_definitions.get(self.query_operation_name)
if not query_type:
return
query_type.add_field(
SCHEMA_ROOT_FIELD_DEFINITION(
gql_type=GraphQLNonNull("__Schema", schema=self)
)
)
query_type.add_field(prepare_type_root_field(self))
for type_definition in self.type_definitions.values():
try:
type_definition.add_field(
TYPENAME_ROOT_FIELD_DEFINITION(
gql_type=GraphQLNonNull(gql_type="String", schema=self)
)
)
except AttributeError:
pass
def reduce_type(
gql_type: Union[str, "GraphQLList", "GraphQLNonNull"]
) -> Union[str, "GraphQLType"]:
"""
Unwraps the GraphQL type and to return the inner type.
:param gql_type: schema type to unwrap
:type gql_type: Union[str, GraphQLList, GraphQLNonNull]
:return: the unwrapped inner schema type
:rtype: Union[str, GraphQLType]
"""
while isinstance(gql_type, (GraphQLList, GraphQLNonNull)):
gql_type = gql_type.gql_type
return gql_type
def non_null_type(self, tree: Tree) -> SchemaNode:
return SchemaNode(
"non_null_type",
GraphQLNonNull(
gql_type=tree.children[0].value, schema=self._schema
),