Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
GraphQLList(gql_type=GraphQLNonNull(gql_type="MyObject")),
"MyObject",
),
(
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
(GraphQLList(gql_type="aType"), True),
(GraphQLNonNull(gql_type="aType"), False),
(GraphQLNonNull(gql_type=GraphQLList(gql_type="aType")), True),
(None, False),
],
)
def test_resolver_factory__shall_return_a_list(field_type, expected):
from tartiflette.resolver.factoryyy import _shall_return_a_list
assert _shall_return_a_list(field_type) == expected
def test_graphql_list_eq():
lst = GraphQLList(gql_type="Name", description="description")
## Same
assert lst == lst
assert lst == GraphQLList(gql_type="Name", description="description")
# Currently we ignore the description in comparing
assert lst == GraphQLList(gql_type="Name")
## Different
assert lst != GraphQLList(gql_type="OtherName")
def test_utils_coercers__get_type_coercers():
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]
def test_graphql_list_repr():
lst = GraphQLList(gql_type="Name", description="description")
assert (
lst.__repr__() == "GraphQLList(gql_type='Name', "
"description='description')"
)
assert lst == eval(repr(lst))
def test_graphql_list_eq():
lst = GraphQLList(gql_type="Name", description="description")
## Same
assert lst == lst
assert lst == GraphQLList(gql_type="Name", description="description")
# Currently we ignore the description in comparing
assert lst == GraphQLList(gql_type="Name")
## Different
assert lst != GraphQLList(gql_type="OtherName")
_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
)
return errors
errors = self._validate(
r_argument_schema_type,
c_argument_schema_type.gql_type,
arg,
path,
errors,
schema,
value_node=value_node,
input_field=input_field,
)
return errors
if isinstance(c_argument_schema_type, GraphQLList):
if isinstance(value_node, NullValueNode):
return errors
arg_values = (
[value_node]
if not isinstance(value_node, ListValueNode)
else value_node.values
)
for arg_value in arg_values:
if isinstance(arg_value, VariableNode):
continue # Handled by another validator
errors = self._validate(
r_argument_schema_type,
c_argument_schema_type.gql_type,
type_node: "TypeNode", schema: "GraphQLSchema"
) -> Union["GraphQLList", "GraphQLNonNull", str]:
"""
Computes an AST type node into its GraphQL representation.
:param type_node: AST type node to treat
:param schema: the GraphQLSchema instance linked to the engine
:type type_node: TypeNode
:type schema: GraphQLSchema
:return: the GraphQL representation of the type node
:rtype: Union[GraphQLList, GraphQLNonNull, str]
"""
inner_type_node = type_node
type_wrappers = []
while isinstance(inner_type_node, (NonNullTypeNode, ListTypeNode)):
if isinstance(inner_type_node, ListTypeNode):
type_wrappers.append(partial(GraphQLList, schema=schema))
elif isinstance(inner_type_node, NonNullTypeNode):
type_wrappers.append(
partial(partial(GraphQLNonNull, schema=schema))
)
inner_type_node = inner_type_node.type
graphql_type = parse_named_type(inner_type_node, schema)
for type_wrapper in reversed(type_wrappers):
graphql_type = type_wrapper(gql_type=graphql_type)
return graphql_type
def list_type(self, tree: Tree) -> SchemaNode:
return SchemaNode(
"list_type",
GraphQLList(gql_type=tree.children[0].value, schema=self._schema),
)