Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 ""
async def ttftt_engine():
@Directive(
"internalCoercionError", schema_name="test_coercion_arguments_errors"
)
class InternalCoercionError:
async def on_argument_execution(
self,
directive_args,
next_directive,
parent_node,
argument_node,
value,
ctx,
):
raise CoercionError("Oopsie")
async def on_post_input_coercion(
self, directive_args, next_directive, parent_node, value, ctx
directive @ninja on FIELD_DEFINITION
type R {
a:String @lol @ninja @deprecated(reason: "NTM")
b:String @lol @deprecated(reason: "NTM3") @ninja
c:String @deprecated(reason: "jjjjjjjjjjjjjj") @lol @ninja
}
type Query {
l: R
}
"""
@Directive("lol", schema_name="test_issue143")
class Lol:
pass
@Directive("ninja", schema_name="test_issue143")
class Ninja:
pass
@pytest.fixture(scope="module")
async def ttftt_engine():
return await create_engine(sdl=_SDL, schema_name="test_issue143")
@pytest.mark.asyncio
async def test_issue143(ttftt_engine):
parent_node,
value: Any,
ctx: Optional[Any],
):
result = await next_directive(parent_node, value, ctx)
if result not in directive_args["choices"]:
raise Exception(
"Value on < %s > is invalid. Valid options are < %s >."
% (
parent_node.name.value,
", ".join(directive_args["choices"]),
)
)
return result
@Directive("debug", schema_name="test_issue133")
class DebugDirective:
async def on_argument_execution(
self,
directive_args: Dict[str, Any],
next_directive: Callable,
parent_node: Union["FieldNode", "DirectiveNode"],
argument_node: "ArgumentNode",
value: Any,
ctx: Optional[Any],
) -> Any:
return await next_directive(parent_node, argument_node, value, ctx)
async def on_post_input_coercion(
self,
directive_args: Dict[str, Any],
next_directive: Callable,
value: Any,
ctx: Optional[Any],
):
return await next_directive(parent_node, value, ctx)
@staticmethod
async def on_pre_output_coercion(
directive_args: Dict[str, Any],
next_directive: Callable,
value: Any,
ctx: Optional[Any],
info: "ResolveInfo",
):
return await next_directive(value, ctx, info)
@Directive("error", schema_name="test_input_directives")
class ErrorDirective:
@staticmethod
async def on_argument_execution(
directive_args: Dict[str, Any],
next_directive: Callable,
parent_node: Union["FieldNode", "DirectiveNode"],
argument_node: "ArgumentNode",
value: Any,
ctx: Optional[Any],
):
raise ValueError("on_argument_execution error")
@staticmethod
async def on_post_input_coercion(
directive_args: Dict[str, Any],
next_directive: Callable,
async def test_issue154(sdl, should_exp, adddir):
class aDirective:
pass
if adddir:
Directive("adirective", schema_name=f"issue154_{sdl}")(aDirective)
if should_exp:
with pytest.raises(GraphQLSchemaError):
Engine(sdl=sdl, schema_name=f"issue154_{sdl}")
else:
e = Engine(sdl=sdl, schema_name=f"issue154_{sdl}")
assert e._schema is not None
def _is_expected_domain(req: "yarl.URL", expected_domain: str) -> bool:
"""
Determines whether or not the user come from the expected domain.
:param req: incoming aiohttp request
:param expected_domain: expected domain from which the user should come
from
:type req: yarl.URL
:type expected_domain: str
:return: whether or not the user come from the expected domain
:rtype: bool
"""
parsed_url = urlparse(str(req.url))
return parsed_url.hostname == expected_domain
@Directive("auth")
class AuthDirective:
"""
Directive to limit access to field and introspection if the user doesn't
come from the expected domain.
"""
async def on_introspection(
self,
directive_args: Dict[str, Any],
next_directive: Callable,
introspected_element: Any,
ctx: Dict[str, Any],
info: "ResolveInfo",
) -> Optional[Any]:
"""
Blocks the introspection if the user doesn't come from the expected
import time
from typing import Any, Callable, Dict, Optional
from tartiflette import Directive
@Directive("rateLimiting")
class RateLimitingDirective:
"""
Directive to rate limit the access to some fields.
"""
def __init__(self) -> None:
self._rate_limit_rules = {}
def _set_new_rate_limit_rule(
self, name: str, max_attempts: int, duration: int, nb_attempts: int = 0
) -> None:
"""
Registers a new rate limit entry.
:param name: identifier of the rate limit
:param max_attempts: maximum allowed attempts during the duration
:param duration: interval before resetting the rate limiting
def bake(schema_name: str, config: Optional[Dict[str, Any]] = None) -> str:
"""
Links the directive to the appropriate schema and returns the SDL related
to the directive.
:param schema_name: schema name to link with
:param config: configuration of the directive
:type schema_name: str
:type config: Optional[Dict[str, Any]]
:return: the SDL related to the directive
:rtype: str
"""
# pylint: disable=unused-argument
Directive("skip", schema_name=schema_name)(SkipDirective())
return '''
"""Directs the executor to skip this field or fragment when the `if` argument is true."""