def bake(schema_name, _config): sdl = """ directive @nonIntrospectable on FIELD_DEFINITION directive @non_introspectable on FIELD_DEFINITION """ Directive(name="nonIntrospectable", schema_name=schema_name)(NonIntrospectable()) Directive(name="non_introspectable", schema_name=schema_name)(NonIntrospectableDeprecated()) 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 ""
async def ttftt_engine_extended(): Directive( name="a_directive", schema_name="test_directive_on_schema_execute_extended", )(ADirective) Directive( name="b_directive", schema_name="test_directive_on_schema_execute_extended", )(BDirective) Resolver( "Query.a", schema_name="test_directive_on_schema_execute_extended" )(resolve_a) return await create_engine( sdl=_SDL + _SDL_EXTEND, schema_name="test_directive_on_schema_execute_extended", )
def bake(schema_name, _config): sdl = """ directive @deprecated( reason: String = "Deprecated" ) on FIELD_DEFINITION | ENUM_VALUE """ Directive("deprecated", schema_name=schema_name)(Deprecated()) return sdl
async def ttftt_engine(): Directive( name="a_directive", schema_name="test_directive_on_schema_execute" )(ADirective) Resolver("Query.a", schema_name="test_directive_on_schema_execute")( resolve_a ) return await create_engine( sdl=_SDL, schema_name="test_directive_on_schema_execute" )
async def ttftt_engine(): Directive(name="a_directive", schema_name="test_directive_schema_on_subscription")(ADirective) Resolver("Query.a", schema_name="test_directive_schema_on_subscription")(resolve_a) Subscription( "Subscription.timer", schema_name="test_directive_schema_on_subscription", )(subscription_timer) return await create_engine( sdl=_SDL, schema_name="test_directive_schema_on_subscription")
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): await create_engine(sdl=sdl, schema_name=f"issue154_{sdl}") else: e = await create_engine(sdl=sdl, schema_name=f"issue154_{sdl}") assert e._schema is not None
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 '''
async 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 """ Directive("timeIt", schema_name=schema_name)(TimeItDirective(config)) return _SDL
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
} """, "a", ) clean_registry.register_sdl("a", full_sdl) schema = SchemaBakery.bake("a") assert schema.has_type(type_name) is expected @pytest.mark.parametrize( "schema_name,where,obj", [ ( "directives_schema", "directives", Directive("my_directive", "directives_schema"), ), ("scalars_schema", "scalars", Scalar("my_scalar", "scalars_schema")), ( "resolvers_schema", "resolvers", Resolver("my_resolver", "resolvers_schema"), ), ], ) def test_schema_registry_register(clean_registry, schema_name, where, obj): SchemaRegistry._register(schema_name, where, obj) with pytest.raises(ImproperlyConfigured) as excinfo: SchemaRegistry._register(schema_name, where, obj)
def bake(schema_name, _config): sdl = "directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT" Directive(name="skip", schema_name=schema_name)(Skip()) return sdl
async def bake(schema_name, config): Directive(name="isoDateNow", schema_name=schema_name)(isoDateNow(config)) return _SDL
def pytest_runtest_setup(item): marker = _get_ttftt_engine_marker(item) if not marker or not getattr(item, "allow_schema_bake", True): return resolvers = marker.kwargs.get("resolvers") or {} type_resolvers = marker.kwargs.get("type_resolvers") or {} subscriptions = marker.kwargs.get("subscriptions") or {} directives = marker.kwargs.get("directives") or {} if not (resolvers or subscriptions or directives): return schema_name = _get_schema_name_from_marker(marker) # Init schema definitions SchemaRegistry._schemas.setdefault(schema_name, {}) # Reset schema resolvers if resolvers: SchemaRegistry._schemas[schema_name]["resolvers"] = {} # Reset schema type_resolvers if type_resolvers: SchemaRegistry._schemas[schema_name]["type_resolvers"] = {} if subscriptions: SchemaRegistry._schemas[schema_name]["subscriptions"] = {} if directives: SchemaRegistry._schemas[schema_name]["directives"] = {} # Apply "Resolver" decorators to resolvers functions for name, implementation in resolvers.items(): Resolver(name, schema_name=schema_name)(implementation) # Apply "TypeResolver" decorators to type resolvers functions for name, implementation in type_resolvers.items(): TypeResolver(name, schema_name=schema_name)(implementation) # Apply "Subscription" decorators to resolvers functions for name, implementation in subscriptions.items(): Subscription(name, schema_name=schema_name)(implementation) # Apply "Directive" decorators to resolvers functions for name, implementation in directives.items(): Directive(name, schema_name=schema_name)(implementation) # Bake resolvers for resolver in (SchemaRegistry._schemas[schema_name].get("resolvers") or {}).values(): resolver.bake(_TTFTT_ENGINES[schema_name]._schema) # Bake type resolvers for type_resolver in ( SchemaRegistry._schemas[schema_name].get("type_resolvers") or {}).values(): type_resolver.bake(_TTFTT_ENGINES[schema_name]._schema) # Bake subscriptions for subscription in ( SchemaRegistry._schemas[schema_name].get("subscriptions") or {}).values(): subscription.bake(_TTFTT_ENGINES[schema_name]._schema) # Bake directives for directive in (SchemaRegistry._schemas[schema_name].get("directives") or {}).values(): directive.bake(_TTFTT_ENGINES[schema_name]._schema) # Re-bake engine schema SchemaRegistry.find_schema_info( schema_name=schema_name)["inst"] = _TTFTT_ENGINES[schema_name]._schema loop = asyncio.new_event_loop() loop.run_until_complete(_TTFTT_ENGINES[schema_name]._schema.bake())
def bake(schema_name, _config): sdl = "directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT" Directive(name="include", schema_name=schema_name)(Include()) return sdl