-
Notifications
You must be signed in to change notification settings - Fork 5
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
Converting compiler to ppx. #3
Comments
graphql_ppx currently parse introspection query, to save you the trouble of making a spec compliant SDL parser, maybe you could use that directly? It contains identical information to SDL |
@thangngoc89 1. We need to write or borrow the parser for client query anyway. In the end, we'll copy here and there of the official code. (Yes, we can borrow some code from graphql_ppx. But when something needs to be tweaked, we need to read graphql-js.) 2. SDL is much much easier to read than JSON. Currently, graphql_ppx interprets GraphQL SDL AST written in JSON. For computers, SDL or JSON doesn't matter. But to human eyes, They cannot be compared. And from SDL, we can understand what we can do with the server faster. And when we use JSON, users need to remember to generate JSON file with npm commands even when they can access their own GraphQL file. (In most monorepo projects, it's really easy to get access to the schema file.) It might be the reason why Google autocompletes graphql_ppx with "graphql_ppx schema file not found". (As for public APIs, we can provide JS tool to convert JSON back to SDL and start from there. We can use the print function.) 3. Finally, we need this library for future Reason GraphQL developers. Currently, every GraphQL library/tool implements partially-featured GraphQL parser for themselves. For future developers, this reality can be overwhelming. We need the parser that they can rely on and create what they want. |
A little story
When I first released and promoted reasonql, I got this question a lot.
My answer was this:
And I thought it was impossible to support fragments with ppx, because ppx only replaces some elements in abstract syntax tree, so it cannot walk through entire file tree and find the appropriate fragment.
I had believed that idea until this morning and was thinking how to persuade other developers. But somehow, I realized that I was wrong if I give up some compile speed for initial and clean compilation. (And I'm not so sure now, but it seems that this speed down isn't that big.)
The Goal
Let's use the fragments snippet in this repo. (I removed
Button.re
here because it's not necessary for now.)Currently, it generates modules like below:
Currently, it copies fragment codes to the query module. But when we change it like this, we don't need this copying process.
Then, it would work without any problem. To handle fragments, we need
Obj.magic
. Even if a fragment changes, every other code will call the changed code without any problem when we set this rule:So, the PostSummary_post should be named in new reasonql_ppx like this:
Post_Fragment_post.
When we add this small rule, everything will be OK.
Todo
ReasonML port of graphql-js. Currently, graphql_ppx can parse graphql client query but cannot parse the schema. reason-graphql has the most similar parser. But it doesn't parse location. Maybe we need to create a reference implementation of the graphql-js. -> Result: Needs implementation. 1) graphql_ppx doesn't parse schema definition. 2) reason-graphql and ocaml-graphql-server don't compile interface. => Check https://github.com/sainthkh/graphql-reason
ppx that generates types and codecs for graphql queries.
move the reasonql.config.js to bsconfig.json
add the option to show generate code on files. -> As reasonql_ppx generates a lot of things, sometimes, we want to see what is going on.
The text was updated successfully, but these errors were encountered: