movio / bramble

A federated GraphQL API gateway
https://movio.github.io/bramble/
MIT License
497 stars 55 forks source link

Cold Start #257

Open Quantumplation opened 4 months ago

Quantumplation commented 4 months ago

I'd like to add the ability to accelerate startup by specifying an initial schema (loaded from disk, for example) so that queries can start being served immediately in the happy path, while the server checks in the background for updates to the schema.

I tried to add this to the code, but quickly got lost, so I figured I'd open a feature request. If you can provide a touch of guidance for how/where to achieve this, I'd be happy to submit a pull request.

pkqk commented 4 months ago

Hi @Quantumplation,

It will require quite a few changes probably, like in your discussions on https://github.com/movio/bramble/issues/231.

I would start with adding something parallel to UpdateSchema that can load a serialized schema and save one to storage periodically.

Then change the startup in Main to trigger that first before starting the periodic update goroutines.

Quantumplation commented 4 months ago

That's where I started, but I wasn't sure how to construct an ExecutableSchema from a string; we make a bunch of requests to other services, and then rebuild the merged schema from the ASTs, but I don't see where the ASTs get built from raw text.

pkqk commented 4 months ago

Have you looked through the gqlparser library, it's mostly in there, it doesn't have many helper methods but you can read schema sources into a string and then use something like:

gqlparser.MustLoadSchema(&ast.Source{Input: str})

to get an *ast.Schema.

The initial creation of ExecutableSchema is in Config.Init so it might be more fitting to put the (de)serialisation there.