-
Notifications
You must be signed in to change notification settings - Fork 19
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
Generate Elm modules from GraphQL queries and mutations #25
Comments
I think as a first step you can do it as web-service like for JSON decoding. User posts GraphQL API endpoint and his query or mutation, the web-service sends an introspection query to fetch the schema and generates a query or mutation with all imports and types/type aliases he needs for it. |
There are at least two independent streams of work here:
I've started on the query parsing task because it's of a manageable size for me at the moment. The analysis and code generation are bigger problems. I have a rough idea about what a solution could look like, but there are lots of hairy details yet to sort out. |
@welf I didn't see your comment before my last post – yes, I'd like to make a tool like that, and it should be simpler to build than the command-line wrapper because it can all be Elm-in-the-browser. However, either way, I think most of the work to be done is in the logic of parsing, analysis, and code generation. |
I've pushed a document-parser branch with a work-in-progress of a parser for query/mutation documents. Right now it just parses simple selection sets (no fragments). You can use |
The document-parser branch should now parse all valid GraphQL documents. The syntax error messages are probably not very helpful right now, but at least it works! Before incorporating this into a release, I will make some fuzz tests that generate valid document ASTs and verify serialize/parse round-trip equality. |
I've started on the task of analyzing document/schema pairs for code generation, and quickly decided that the best first step is to implement document validation. Not only is it perfectly reasonable to expect that this library should validate your query/mutation document against your schema before generating code from it, but most of the analysis logic required for code generation is also required for validation. Validation is very well defined in the GraphQL spec, which means that the work is pretty straightforward (if a bit tedious at times). Once that work is done, we'll have a nice toolbox of functions that can be reused to analyze documents for the purposes of code generation. I've got some untested work-in-progress code in the |
@jamesmacaulay I've looked at the work you've done on the |
I am rooting for you guys. This would be great to have. |
@Vynlar Sorry for the delayed response. The |
People want to be able to write their queries and mutations in GraphQL. I previously thought that #17 would be a worthwhile stepping-stone to this, but ongoing discussion has made it more clear that it's just not worth it.
Requirements:
.graphql
files in their project, along with aschema.json
obtained by an introspection query to the GraphQL server. The command-line program should be able to help with issuing the introspection request and fetching theschema.json
from the server.The text was updated successfully, but these errors were encountered: