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 bake(schema_name, config):
Directive("Blah", schema_name=schema_name)(BlahDir(config))
Scalar("NinjaGo", schema_name=schema_name)(NinjaGo)
Resolver("Lol.ninja", schema_name=schema_name)(resolver_of_lol_ninja)
return _SDL
def bake(schema_name, config):
Scalar("DefaultRawInt", schema_name="coercion")(IntScalar())
Scalar("DefaultRawString", schema_name="coercion")(StringScalar())
Scalar("Boolean", schema_name="coercion")(BooleanScalar())
Scalar("Float", schema_name="coercion")(FloatScalar())
Scalar("Int", schema_name="coercion")(IntScalar())
Scalar("String", schema_name="coercion")(StringScalar())
Directive("debug", schema_name="coercion")(DebugDirective())
Directive("lowercase", schema_name="coercion")(LowercaseDirective())
Directive("increment", schema_name="coercion")(IncrementDirective())
Directive("concatenate", schema_name="coercion")(ConcatenateDirective())
Directive("mapToValue", schema_name="coercion")(MapToValueDirective())
return ""
class InternalCoercionError:
async def on_post_input_coercion(
self, directive_args, next_directive, parent_node, value, ctx
):
raise CoercionError("Oopsie")
@Directive(
"customCoercionError", schema_name="test_coercion_variables_errors"
)
class CustomCoercionError:
async def on_post_input_coercion(
self, directive_args, next_directive, parent_node, value, ctx
):
raise ValueError("Oopsie")
@Scalar("FirstErrorScalar", schema_name="test_coercion_variables_errors")
@Scalar("SecondErrorScalar", schema_name="test_coercion_variables_errors")
class ErrorScalars(ScalarString):
pass
return await create_engine(
sdl=_SDL, schema_name="test_coercion_variables_errors"
)
def bake(schema_name, config):
Scalar("DefaultRawInt", schema_name="coercion")(IntScalar())
Scalar("DefaultRawString", schema_name="coercion")(StringScalar())
Scalar("Boolean", schema_name="coercion")(BooleanScalar())
Scalar("Float", schema_name="coercion")(FloatScalar())
Scalar("Int", schema_name="coercion")(IntScalar())
Scalar("String", schema_name="coercion")(StringScalar())
Directive("debug", schema_name="coercion")(DebugDirective())
Directive("lowercase", schema_name="coercion")(LowercaseDirective())
Directive("increment", schema_name="coercion")(IncrementDirective())
Directive("concatenate", schema_name="coercion")(ConcatenateDirective())
Directive("mapToValue", schema_name="coercion")(MapToValueDirective())
return ""
def bake(schema_name, config):
Scalar("DefaultRawInt", schema_name="coercion")(IntScalar())
Scalar("DefaultRawString", schema_name="coercion")(StringScalar())
Scalar("Boolean", schema_name="coercion")(BooleanScalar())
Scalar("Float", schema_name="coercion")(FloatScalar())
Scalar("Int", schema_name="coercion")(IntScalar())
Scalar("String", schema_name="coercion")(StringScalar())
Directive("debug", schema_name="coercion")(DebugDirective())
Directive("lowercase", schema_name="coercion")(LowercaseDirective())
Directive("increment", schema_name="coercion")(IncrementDirective())
Directive("concatenate", schema_name="coercion")(ConcatenateDirective())
Directive("mapToValue", schema_name="coercion")(MapToValueDirective())
return ""
from tartiflette import Scalar
from bson import ObjectId
@Scalar("Json")
class Json:
@staticmethod
def coerce_input(val):
return val
@staticmethod
def coerce_output(val):
return val
@Scalar("ObjectId")
class ObjectIdScalar:
@staticmethod
def coerce_input(val):
return ObjectId(val)
@staticmethod
def coerce_output(val):
return str(val)
@Scalar("ID")
class IDClass:
@staticmethod
def coerce_input(val):
return val
@staticmethod
JsonScalar = Scalar("Json")
@JsonScalar
class JsonClass:
@staticmethod
def coerce_input(val):
return val
@staticmethod
def coerce_output(val):
return val
def parse_literal(self, ast: "Node") -> Union[str, "UNDEFINED_VALUE"]:
return self.coerce_input(ast.value)
AnyScalarScalar = Scalar("AnyScalar")
@AnyScalarScalar
class AnyScalarClass:
@staticmethod
def coerce_input(val):
if val == 'true':
return True
elif val == 'false':
return False
else:
try:
return float(val)
except Exception:
return str(val)
@staticmethod
def coerce_output(val):
@staticmethod
def coerce_output(val):
return val
@Scalar("ObjectId")
class ObjectIdScalar:
@staticmethod
def coerce_input(val):
return ObjectId(val)
@staticmethod
def coerce_output(val):
return str(val)
@Scalar("ID")
class IDClass:
@staticmethod
def coerce_input(val):
return val
@staticmethod
def coerce_output(val):
return val
def bake(schema_name: str, config: Optional[Dict[str, Any]] = None) -> str:
"""
Links the scalar to the appropriate schema and returns the SDL related
to the scalar.
:param schema_name: schema name to link with
:param config: configuration of the scalar
:type schema_name: str
:type config: Optional[Dict[str, Any]]
:return: the SDL related to the scalar
:rtype: str
"""
# pylint: disable=unused-argument
Scalar("DateTime", schema_name=schema_name)(ScalarDateTime())
return '''
"""The `DateTime` scalar type represents a date time object"""