Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for input_field_name, input_field_result in zip(input_fields, results):
if input_field_result is SKIP_FIELD:
continue
if is_invalid_value(input_field_result):
return CoercionResult(value=UNDEFINED_VALUE)
input_field_value, input_field_errors = input_field_result
if is_invalid_value(input_field_value):
return CoercionResult(value=UNDEFINED_VALUE)
if input_field_errors:
errors.extend(input_field_errors)
elif not errors:
coerced_values[input_field_name] = input_field_value
return CoercionResult(value=coerced_values, errors=errors)
:param variables: the variables provided in the GraphQL request
:param path: the path traveled until this coercer
:type parent_node: Union[VariableDefinitionNode, InputValueDefinitionNode]
:type node: Union[ValueNode, VariableNode]
:type ctx: Optional[Any]
:type scalar_type: GraphQLScalarType
:type variables: Optional[Dict[str, Any]]
:type path: Optional[Path]
:return: the computed value
:rtype: CoercionResult
"""
# pylint: disable=unused-argument
try:
value = scalar_type.parse_literal(node)
if not is_invalid_value(value):
return CoercionResult(value=value)
except Exception: # pylint: disable=broad-except
pass
return CoercionResult(value=UNDEFINED_VALUE)
)
]
)
except Exception as e: # pylint: disable=broad-except
return CoercionResult(
errors=[
coercion_error(
f"Expected type < {scalar_type.name} >",
node,
path,
sub_message=str(e),
original_error=e,
)
]
)
return CoercionResult(value=coerced_value)
async def wrapper(
parent_node: Union[
"VariableDefinitionNode", "InputValueDefinitionNode"
],
node: "Node",
value: Any,
ctx: Optional[Any],
**kwargs,
) -> "CoercionResult":
if value is None:
return CoercionResult(value=None)
return await coercer(parent_node, node, value, ctx, **kwargs)
:param value: the raw value to compute
:param ctx: context passed to the query execution
:param enum_type: the GraphQLEnumType instance of the enum
:param path: the path traveled until this coercer
:type parent_node: Union[VariableDefinitionNode, InputValueDefinitionNode]
:type node: Node
:type value: Any
:type ctx: Optional[Any]
:type enum_type: GraphQLEnumType
:type path: Optional[Path]
:return: the coercion result
:rtype: CoercionResult
"""
try:
enum_value = enum_type.get_value(value)
return CoercionResult(
value=await enum_value.input_coercer(parent_node, value, ctx)
)
except Exception: # pylint: disable=broad-except
return CoercionResult(
errors=[
coercion_error(
f"Expected type < {enum_type.name} >",
node,
path,
did_you_mean(
get_close_matches(
str(value),
[enum.value for enum in enum_type.values],
n=5,
)
if input_field_name not in input_fields:
errors.append(
coercion_error(
f"Field < {input_field_name} > is not defined by type "
f"< {input_object_type.name} >",
node,
path,
did_you_mean(
get_close_matches(
input_field_name, input_fields.keys(), n=5
)
),
)
)
return CoercionResult(value=coerced_values, errors=errors)
]
)
if has_value:
coerced_value, coerce_errors = await input_coercer(
variable_definition_node, value, ctx
)
if coerce_errors:
for coerce_error in coerce_errors:
if isinstance(coerce_error, CoercionError):
coerce_error.message = (
f"Variable < ${var_name} > got invalid value "
f"< {value} >; {coerce_error.message}"
)
return CoercionResult(errors=coerce_errors)
return CoercionResult(value=coerced_value)
return UNDEFINED_VALUE
if not directives:
return coercion_result
value, errors = coercion_result
if errors:
return coercion_result
try:
return CoercionResult(
value=await directives(
parent_node, value, ctx, context_coercer=ctx
)
)
except Exception as raw_exception: # pylint: disable=broad-except
return CoercionResult(
errors=[
graphql_error_from_nodes(
str(raw_exception),
node,
original_error=(
raw_exception
if not is_coercible_exception(raw_exception)
else None
),
)
for raw_exception in (
raw_exception.exceptions
if isinstance(raw_exception, MultipleException)
else [raw_exception]
)
:type parent_node: Union[VariableDefinitionNode, InputValueDefinitionNode]
:type node: Node
:type value: Any
:type ctx: Optional[Any]
:type input_field: GraphQLInputField
:type path: Path
:return: the coercion result
:rtype: Union[CoercionResult, UNDEFINED_VALUE]
"""
if is_invalid_value(value):
if input_field.default_value is not None:
return await input_field.literal_coercer(
parent_node, input_field.default_value, ctx
)
if input_field.graphql_type.is_non_null_type:
return CoercionResult(
errors=[
coercion_error(
f"Field < {path} > of required type "
f"< {input_field.gql_type} > was not provided",
node,
)
]
)
return UNDEFINED_VALUE
return await input_field.input_coercer(
parent_node, node, value, ctx, path=path
)
:rtype: CoercionResult
"""
if not node:
return CoercionResult(value=UNDEFINED_VALUE)
if isinstance(node, NullValueNode):
return CoercionResult(value=None)
if isinstance(node, VariableNode):
if not variables:
return CoercionResult(value=UNDEFINED_VALUE)
value = variables.get(node.name.value, UNDEFINED_VALUE)
if is_invalid_value(value) or (value is None and is_non_null_type):
return CoercionResult(value=UNDEFINED_VALUE)
return CoercionResult(value=value)
return await coercer(
parent_node, node, ctx, variables=variables, **kwargs
)