Skip to content
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

Enhancements #68

Closed
orefalo opened this issue May 10, 2020 · 29 comments
Closed

Enhancements #68

orefalo opened this issue May 10, 2020 · 29 comments
Labels
enhancement New feature or request

Comments

@orefalo
Copy link

orefalo commented May 10, 2020

Nice implementation - congrats
Surprised to see federation built in

Would be nice to see:

  1. Support for SDL format - https://github.com/orefalo/graphql-shorthand-parser
  2. Support for @annotations

With basic annotations (http proxy, oauth validation, structure getter) you can support 70-80% of the typical graphql use cases.

@sunli829
Copy link
Collaborator

Do you want to generate some framework code through GraphQL Schema DSL?

@orefalo
Copy link
Author

orefalo commented May 10, 2020

Hi, tks for the quick reply.
That could work. the point is, most of my implementations today are in JS. I decided to use the DSL notation to abstract the graphQL implementation. So yes a code generator would definitely help and be very useful to a broader audience.

@sunli829
Copy link
Collaborator

I thought about it, in fact, rust has another library to do this, https://github.com/davidpdrsn/juniper-from-schema, but it does not support async-graphql. The biggest problem is that this type of code generation will create new types, but these types of IDEs do not recognize them, so they cannot be automatically completed. I think this increases the difficulty of writing code, so I am still considering whether I really need to implement this. 😁

@nicolaiunrein nicolaiunrein added the enhancement New feature or request label May 10, 2020
@phated
Copy link
Contributor

phated commented May 10, 2020

Instead of using macros to generate the rust code, there could be a command line tool that outputs the rust code (like diesel-cli does for the database). I believe the new parser work that @sunli829 did could be used to support that tool.

@nicolaiunrein
Copy link
Collaborator

nicolaiunrein commented May 10, 2020

You mean a tool that - given a GQL Schema and access to your business logic - generates some boilerplate for your api before compilation?

@sunli829
Copy link
Collaborator

@phated I understand what you mean, this way can really solve the problem that ide can't recognize the type. After I am busy with the work at hand, I will study the feasibility. 😁

@orefalo
Copy link
Author

orefalo commented May 11, 2020

Thank you. For the context. I built a GraphQL UI designer - it generates SDL code. Ideally would love to have it generate RUST code for the same model. Which brings me to two questions:

  1. Why can't rust read the SDL like javascript does? Is there any limitations in the language?
  2. Well, a generator can be written in any language - if you highlight the patterns, I could even write it in JS. Remember I already have the SDL parser.
    Cheers

@sunli829
Copy link
Collaborator

What I understand is that you have a tool that can automatically generate GraphQL code for js, including the implementation of solving functions. Now you want to generate rust?

@sunli829
Copy link
Collaborator

sunli829 commented May 11, 2020

GraphQL UI designer contains the definition of the data source, so you can generate the entire code, similar to hasura? 😁

@orefalo
Copy link
Author

orefalo commented May 11, 2020

The tool goes from UI UML like models -> GraphQL SDL

from there:
hasura takes that SDL and creates a persistent implementation on the database
my own JS graphql server (which has nothing special), takes the SDL and creates a volatile implementation.

Now, I would love to see you implementation read the SDL, but it doesn't at this point.
Therefore two options:

  1. have you implement the functionality - may take some time
  2. create a code generator (you mentioned it) - the point here is that this generator doesn't necessarily have to be built in rust. so using some of the opensource projects I already build, we could quickly implement a "prototype"

@sunli829
Copy link
Collaborator

I have seen the code of graphql-shorthand-parser, if I have not misunderstood, it is a GraphQL Schema parser, and your purpose is to be able to use this parser result (AST) to generate rust code, is that true? 😁

@sunli829
Copy link
Collaborator

If I understand correctly above, there is a small problem here. If I hope that the tools from SDL to Rust code can be used as rust macros in the future, js cannot do this.

@sunli829
Copy link
Collaborator

Sorry, I just understood the meaning of SDL, which is Schema Definition Language.

@orefalo
Copy link
Author

orefalo commented May 11, 2020

No worries, I think they call it IDL but anyways.. glad you got it

On my side, I am really not familiar with Rust... what are macros?

@sunli829
Copy link
Collaborator

There is a syntax in javascript, @ annotations, also in python and java. The rust macro can do the same thing, the difference is that it is completed at compile time.

@orefalo
Copy link
Author

orefalo commented May 11, 2020

I see. that's actually one of the "missing" features I identified up on the thread. Glad it's there, then.
Back to our discussion. in your opinion, is it worth supporting SDL in your Rust implementation?

@sunli829
Copy link
Collaborator

I think it's worth it. After all, some developers like "Schema first", so I'm already thinking about how to implement this. 😁

@sunli829
Copy link
Collaborator

And when I started to do this, I thought I would finish it soon.

@orefalo
Copy link
Author

orefalo commented May 11, 2020

When/if you implement it..

I found this library - https://github.com/kevinmehall/rust-peg
Here are my grammar files - https://github.com/orefalo/graphql-shorthand-parser/tree/master/src

Cheers

@sunli829
Copy link
Collaborator

Thank you very much. 🍺

@kellpossible
Copy link

Alternatively, some way to export the Schema in the schema format at build time would be nice.

@sunli829
Copy link
Collaborator

Export sdl for the client?

@kellpossible
Copy link

Yes, I haven't used graphql before, this is my first time, so forgive me if I'm missing something, I was thinking exporting the schema definition schema.graphql to be consumed by the client at build time. That way there is still only a single definition. Perhaps this would be easier to do than implementing an SDL parser, and generating the schema for the server from that?

@phated
Copy link
Contributor

phated commented Jun 12, 2020

@kellpossible the common practice is just to use a tool against your development environment and check in the schema.graphql. I use https://www.npmjs.com/package/graphql-cli/v/3.0.14 (make sure to use the older version because the new one removed features)

@sunli829
Copy link
Collaborator

@kellpossible the common practice is just to use a tool against your development environment and check in the schema.graphql. I use https://www.npmjs.com/package/graphql-cli/v/3.0.14 (make sure to use the older version because the new one removed features)

I think it's better that way.

@kellpossible
Copy link

kellpossible commented Jun 13, 2020

@phated thanks ooh okay that does sound good, so the idea is that using the CLI tool you can pull the schema from the graphql server/api and updates the schema file that way? A pity it is an older version.

@Weasy666
Copy link
Contributor

Weasy666 commented Sep 7, 2020

So...is it currently possible to use async-graphql with the schema first approach? I couldn't find a way to parse and use a schema file.

@sunli829
Copy link
Collaborator

sunli829 commented Sep 7, 2020

So...is it currently possible to use async-graphql with the schema first approach? I couldn't find a way to parse and use a schema file.

https://docs.rs/crate/codegen-for-async-graphql/0.2.6

I haven't used this, but it seems to be schema first.

@Weasy666
Copy link
Contributor

Weasy666 commented Sep 7, 2020

Ah...ok, so i have to use an external lib for that. Thanks for the info.

Yes, that is schema first. Just for others reading this, it is working, but has a few caveats. It currently is not able to generate code for a required array with required elements, i.e. [Branch!]! (see Issue #5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants