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

about graphql-Java #89

Closed
jxnu-liguobin opened this issue May 21, 2020 · 7 comments
Closed

about graphql-Java #89

jxnu-liguobin opened this issue May 21, 2020 · 7 comments

Comments

@jxnu-liguobin
Copy link

Excuse me, we use graphql-java a lot,can this plugin support graphql-Java with A PR? Although I don't know if graphql-Java can provider parser or validation

@felixbr
Copy link
Collaborator

felixbr commented May 21, 2020

Hello, PRs are always welcome. 🙂

Could you describe your use-case (or goal) for the graphql-java support you want to add? Maybe there's already a way to do it.

@jxnu-liguobin
Copy link
Author

I just want to convert schema to scala case class, because writing two much case class are boring. In theory, schema standards are the same in different implementations of graphql, so they can already support? I'm not sure, because i found a issue has open #19

@felixbr
Copy link
Collaborator

felixbr commented May 21, 2020

You can already generate case classes for a given graphql schema (on the client-side). In your case the schema would be pulled from a graphql-java server. Check out the Code Generation part of the readme.

The issue you linked is similar but instead of generating the client-side code they want to generate a sangria-server from a given schema. I assume you don't need that because you already have a graphql-server (using graphql-java).

Hope this helps 🙂

@jxnu-liguobin
Copy link
Author

jxnu-liguobin commented May 21, 2020

sry ,It may not be described clearly, but I think I also need the server code ,that is data response to frontend.
1.fetcher response

ProjectInfo(......) or grpc Dto ProjectInfoDto

2.server schema like this

type ProjectInfo { id: HashId! name: String! logo: String @option createdAt: DateTime! }

3.then i need write case class for response, this is what i want to auto generate
case class ProjectInfo( id: Long, name: String, logo: Option[String], createdAt: ZonedDateTime)

That is a pure back-end service, exposing a /grqphql interface to the frontend.
I hava two cases by Repository implements

1.one case is (dao call grpc)
convert ProjectInfoDto => schema (graphql SDL ) when grpc Dto was exists, i want no longer need to write SDL
or 「grpc message schema => schema (graphql SDL )」(because this graphql service only as a API, Dto is the same as SDL)
2.another case is (dao call database)
schema => case class
or if i generate code from datebase table, i can no longer write SDL too.
case class => schema

@felixbr
Copy link
Collaborator

felixbr commented May 21, 2020

I may still not fully understand what you're trying to do. 😅

I think you are writing a graphql-server (using sangria; with Scala) which is used by the frontend (in the Browser; not Scala). You also said that you want to generate/derive the graphql schema from some other schema like a grpc definition or database schema.

If this is the case this plugin sadly cannot help you much right now. But sangria already has some ways to eliminate boilerplate code:

  • sangria provides a nice DSL to define schemas and as long as you have a way to access a structured form of a grpc definition or database schema, it should be possible to write code that converts that into a sangria schema definition. (I heard Twitter does this but I haven't seen it myself; ping @sachee).
  • When you already have case classes somewhere (manually written or generated by some other plugin), you can use sangria macro derivation to derive the graphql schema from it.
  • When you already have a graphql schema (SDL), you can use sangria schema materialization to generate code stubs for it. So if you find a tool that converts your grpc definition into a graphql schema (SDL), this might be useful.

Both of the mentioned options directly use sangria. The plugin here (sbt-graphql) isn't needed for that. But it is useful to do other things:

  • Generate code if you're using Scala as a client to a graphql API
  • Write a sangria-schema as SDL to a file (for code-review)
  • Validate a sangria-schema against some graphql SDL (e.g. to match a "SDL-spec" or to check for breaking changes)

edit: I also don't understand what this has to do with graphql-java, sorry 😕

@felixbr
Copy link
Collaborator

felixbr commented May 21, 2020

I forgot to link to this sangria issue where its creator talks about the schema materialization: sangria-graphql/sangria#381

@jxnu-liguobin
Copy link
Author

Okay, thank you, 😯maybe Sangria can do this,but i write graphql-server not Sangria,

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

No branches or pull requests

2 participants