-
Notifications
You must be signed in to change notification settings - Fork 52
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
Make it possible to serve multiple graphql schemas on a node #91
Comments
First part is solving namespaces for injections, then the execution. Files of interest:
|
I'm very interested in this possibility. Without a deep analysis, I guess it would be a matter of allowing multiple instances of graphql_schema, and updating all related functions to carry the name of the schema instance (an atom, that would be the same as the registered module in my mind). |
We have not started this yet. Keep one
Other things which requires work here:
The I'd suggest we might want to start by introducing the If you need, I can write that thing up as an issue to be solved as well, so we can get a PR going for it. |
Thank you for the directions. I started a first attempt but the needed changes are massive... even on the yrl parser I'm not familiar with... ...no sure if this is the right way, |
Yeah, that approach ain't gonna work in the long run. But it is not in vain in that it spotlights a number of things we want to do to the code base. I think the right approach is to first do some refactoring runs over the parts that needs change. Then propose those as PRs and get them into the code base. Once that is done, you can probably add namespaces in a fairly small patch in the end because the code has been "phase shifted" into the right direction. Patch considerationsThe main problem with the patch is that it doesn't use In the system, Now, as written above, there are situations where However: Before embarking on the above, there are at least three areas of the code which will need refactoring. This should be done first in PRs before attempting the namespace changes in order to cut down such a PR to a manageable size. The idea is that what we cannot reach in one commit/PR, we can reach over several.
Rationale: The grammar file does a lookup on the schema. This is bad form and a hack. It builds a tight coupling between the schema system and the parser where they could have been isolated. Rather than doing a lookup on a type
Rationale: I recently needed to know in which "context" a directive is used. I used the variable name
Rationale: Prepare the schema system for multiple namespaces. Define
such that it works with the old code, but allow the
Other considerationsWe may want to think about the API up front. In the tutorial, we have this section In the code. Clearly, the system will call with a context Final remarksFeel free to ask more questions if something is unclear. But from what I could skim out of your patch, this is probably going to provide you with a path that is easier to tread. In short: split it into multiple PRs and handle each section by itself, while keeping the system without functional changes. Once every refactoring is in, make the "real" patch which should now be easy to write since everything is phased correctly. [0] Another way of saying it: the |
Instead of introducing namespaces, could this app be modified to run multiple instances of itself? One approach would be:
This might be less intrusive than namespaces, and also gives the ability to start and stop different graphql endpoints at will. |
I think your approach would work too, and I'll happily take that approach as well. Essentially, you could just run one |
- Multiple endpoints may now run independently each with their own schema process. - Global context has been replaced with `endpoint_context` type containing schema PID and ets tables. - New API in `graphql` with `ep_` prefix (ex `ep_execute()`). These take an `endpoint_context`. - New API in `graphql` with `p_` prefix (ex `p_execute()`). These take a schema PID/atom. This is most useful when you have a named schema process that can be referred to by its name atom. - Existing API wraps the `ep_` API and uses the named schema process `graphql_default_endpoint` - `endpoint_context` is passed inside `Ctx` maps. The variable `EP` is added when `endpoint_context` is needed but no `Ctx` is available. - ct tests pass - addresses case jlouis#91
Currently it is only possible to serve one GraphQL schema on an Erlang node. It would be useful to be able to run multiple GraphQL schemas on a single node for a couple of reasons:
This would require all the internal lookups to be name-spaced.
The text was updated successfully, but these errors were encountered: