New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tartiflette 0.12 compatibility #32
Comments
Hi @abusi, can I ask why it is now impossible to create an engine synchronously — or rather, what makes creating an engine asynchronously necessary? Thanks! Edit: okay, I think I've found the answer in the engine docs, actually. My question is then, why do we need to pass parameters to This would allow this package (and others?) to reuse the |
Hi @florimondmanca I was in the process of making starlette compatible with 0.11 by passing a partial as a startup hanlder and then do the We removed the parameters from the engine cause they are not needed by the engine itself but by subcomponent, it was bothering me to add things to self that weren't usefull for self. They are all transitive parameters that's why I moved them to the I understand your frustration here and I didn't think it would be such a big deal. I'll propose a PR to you with tartiflette 0.11 compatibility, I didn't had the time to finish it, but I'll do it as soon as I can (in the coming days). |
Thanks for your answer!
Yup, and you're 100% right!
I'm not angry at all about the change, just trying to understand the decision. :-) Sorry if it came across as rough!
Thanks! Just a heads up in the associated Tartiflette issue/PR would be enough, I wouldn't want to slow things down.
Sounds good! FYI, I pushed a complete overhaul of the internals of Here's my idea for an updated from starlette.routing import Lifespan
class TartifletteApp:
def __init__(
self,
sdl: str,
*,
graphiql: typing.Union[bool, GraphiQL] = True,
path: str = "/",
schema_name: str = "default",
modules: typing.List = None,
):
if graphiql is True:
graphiql = GraphiQL()
routes = []
if graphiql and graphiql.path is not None:
routes.append(Route(path=graphiql.path, endpoint=GraphiQLEndpoint))
graphql_route = Route(path=path, endpoint=GraphQLEndpoint)
routes.append(graphql_route)
self.engine = Engine()
self.app = Lifespan(GraphQLMiddleware(
Router(routes=routes),
engine=self.engine,
graphiql=graphiql,
graphql_path=graphql_route.path,
))
@self.app.on_event("startup")
async def prepare_engine():
await self.engine.cook(
sdl=sdl, modules=modules, schema_name=schema_name
)
async def __call__(self, scope: Scope, receive: Receive, send: Send):
await self.app(scope, receive, send) |
By the way, note that the If we were able to pass an Here's how it could simplify def __init__(
self,
engine: Engine
*,
graphiql: typing.Union[bool, GraphiQL] = True,
path: str = "/",
):
if graphiql is True:
graphiql = GraphiQL()
routes = []
if graphiql and graphiql.path is not None:
routes.append(Route(path=graphiql.path, endpoint=GraphiQLEndpoint))
graphql_route = Route(path=path, endpoint=GraphQLEndpoint)
routes.append(graphql_route)
self.engine = engine
self.app = Lifespan(GraphQLMiddleware(
Router(routes=routes),
engine=self.engine,
graphiql=graphiql,
graphql_path=graphql_route.path,
))
self.app.add_event_handler("startup", self.engine.cook) I insist because while I can see how storing data in Is it too late to consider a switch? |
You're making good points with this, let me think about it a little bit more. I'll get back to you during the day. |
tartiflette/tartiflette#244 @florimondmanca You were right, it gives us more flexibility. |
@florimondmanca Do you still need help with the 0.11.x migration ? I don't have time to finish my work on it, I see that you already have ideas for it. If you think it can wait a bit, i'll do it next week. |
I think I can take it over. Feel free to push your work to a branch and I'll be able to take it from there this week/this weekend. :-) Thanks! |
Problem description
I noticed that Tartiflette 0.11 was out, and there are a few changes.
The major one I see is that engine creation is now asynchronous and must be done via
create_engine()
.This means that the current
engine
parameter toTartifletteApp()
isn't appropriate anymore, because we can't create a rawEngine
anymore (at least not in a sync context which is typically where the app is registered).Alternatives
First, options previously delegated to
Engine
must now be handled byTartifletteApp
. This can be done in two ways:TartifletteApp
(similar to whattartiflette-aiohttp
currently does things), store them and then pass them tocreate_engine()
.Engine
helper and pass its kwargs down tocreate_engine()
.I personally prefer 2) because it keeps things organized and is more explicit/IDE-friendly.
Next, we're going to have to defer engine creation/"cooking" to when the app starts up. This can be implemented with Starlette's
Lifespan
helper.Additional context
The text was updated successfully, but these errors were encountered: