-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Hack Idea: Runtime Relay Compiler #3548
Comments
@poteto made a great point internally, that this is basically a solution in search of a problem. It presupposes that build tooling setup is a meaningful impediment to adoption, which may or may not actually be true. Additionally, there are many other impediments (poor documentation generally for example) which this would not help address. So one thing that I'd appreciate the communities feedback on is: Do you have any reason to believe/doubt that build tooling setup is a significant impediment to people trying out, and eventually adopting Relay? |
devs forget or don't understand babel plugin or why to run relay compiler |
This sounds similar to what Relay Classic used to do!
Do you mean try it out within their own codebase, or just try it out in a standalone codebase to get a feel for it? The latter could more easily be done using something like CodeSandbox or repl.it, I think. For trying it out locally in a standalone codebase, I don't think it's hard to get working with create-react-app, just creating the server-side is the tricky bit (although people could use public GraphQL servers for testing purposes) |
The idea would be to allow people to try it out in their own app without needing to setup the compiler or Babel transform. For trying out a demo app we have https://codesandbox.io/s/relay-sandbox-nxl7i?file=/src/TodoApp.tsx Good point about the pain of spinning up a server being a big pain point. Are there any public GraphQL servers that have permissive CORS headers? |
I really like the idea of being able to run Relay without needing to set up a compiler, though I think I agree with your later comment about thinking if this is impactful enough for adoption. I do think a compiler is a slight barrier of entry, but most other GraphQL clients require code generation already. Maybe the issue is more around explaining/understanding more when the compiler is needed to be run, what it does, and how does it play with the runtime code. I like the idea that the new work with the IDE aims to do, where it runs the compiler for you automatically and devs don't have to even think about that, while still getting all the benefits. Specific to the runtime compiler:
Could they be surfaced with an error overlay, similar to how create-react-app does it? |
After discussion, I think this is probably not worth pursuing. Thanks everyone for the input. |
In this issue I'm proposing an in-browser version of the Relay compiler which could allow people to try out Relay (with some restrictions) without needing to setup Babel transform or compiler. I'm curious to hear from the community how valuable (or not) and option like this would be given the limitations.
Motivation: We believe that Relay’s main impediment to broader OSS adoption, and thus broader industry impact is the complexity of the initial setup. The largest part of this is the requirement that new users must get the compiler and Babel transform working for their code base before they even start to try Relay. If we could allow users to try Relay’s APIs first and only configure the compiler and Babel transform after/if they are convinced of its value, we could increase our industry impact.
Hypothesis If a user can abide by the following restrictions, we can support most of Relay’s existing APIs.
graphql
tagged template literals must be in the module scopeSummary: We could provide a new NPM module which exposes a custom
graphql
tagged template literal which collects module scoped GraphQL strings and — right before we begin rendering — transforms them to Relay runtime modules using a Wasm version of the compiler.Proposed Implementation
We create a new NPM module which exposes a
graphql
tagged template and acompile(schema: string)
function. The new module maintains a module scope registry (map object) from each GraphQL document string to that document’s runtime object. When thegraphql
tagged template is called it immediately creates an empty object (to be mutated later), adds it to the registry and returns that empty object.After all modules have been loaded, but before we start to render — for example right before the initial render of the app — the user must call the new module’s
compile(schema)
function.When the
compile(schema)
function is called, it collects up all the documents that have been seen so far and the schema string and calls a method on a Wasm version of the compiler. The compiler returns an array of strings (one for each document, in the same order), each string contains the JavaScript for that document’s runtime module. Those modules areeval()
ed and the resulting module is merged into the empty object (Object.assign()
) created by the call to thegraphql
tagged template.The result is that the in-browser compiler would have access to all GraphQL documents and by the time any of the Relay runtime data is read by Relay, it would be available.
Rough Code for the New Module:
A Component Using the New Module
A Project Root Using the New Module
Arguments In Favor
Features of this proposal:
graphql
tagged template and removing the runtime call tocompile(schema)
Arguments Against
Reasons we might not want to consider this proposal:
Overall, the limitations of this setup might be too complex to communicate via documentation or runtime checks.
The text was updated successfully, but these errors were encountered: