Coder Social home page Coder Social logo

Enhancements about async-graphql HOT 29 CLOSED

async-graphql avatar async-graphql commented on April 28, 2024 1
Enhancements

from async-graphql.

Comments (29)

sunli829 avatar sunli829 commented on April 28, 2024 2

@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. 😁

from async-graphql.

phated avatar phated commented on April 28, 2024 2

@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)

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024 1

@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.

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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

from async-graphql.

orefalo avatar orefalo commented on April 28, 2024

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.

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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. 😁

from async-graphql.

phated avatar phated commented on April 28, 2024

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.

from async-graphql.

nicolaiunrein avatar nicolaiunrein commented on April 28, 2024

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

from async-graphql.

orefalo avatar orefalo commented on April 28, 2024

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

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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?

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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

from async-graphql.

orefalo avatar orefalo commented on April 28, 2024

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"

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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? 😁

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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.

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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

from async-graphql.

orefalo avatar orefalo commented on April 28, 2024

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?

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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.

from async-graphql.

orefalo avatar orefalo commented on April 28, 2024

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?

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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

from async-graphql.

orefalo avatar orefalo commented on April 28, 2024

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

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

Thank you very much. 🍺

from async-graphql.

kellpossible avatar kellpossible commented on April 28, 2024

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

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

Export sdl for the client?

from async-graphql.

kellpossible avatar kellpossible commented on April 28, 2024

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?

from async-graphql.

kellpossible avatar kellpossible commented on April 28, 2024

@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.

from async-graphql.

Weasy666 avatar Weasy666 commented on April 28, 2024

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.

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

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.

from async-graphql.

Weasy666 avatar Weasy666 commented on April 28, 2024

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).

from async-graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.