GraphQL Java Class Generator [closed]
Asked Answered
T

1

9

I want to dive into graphQL using Java. I want to query an existing graphQL Service. From what I have found so far are ways to generate the graphQL schemafiles either in JSON or IDL from your POJO classes, but not the other way round....? From what I have understood so far, I would have to create the java classes myself that "represent" the objects I would receive from a query. But the service I want to use has tons of endpoints and queries and the need of writing each pojo class myself sounds like I have missed something... I assume there must be a way to generate stubs like I am used to from REST API frameworks using swagger or yaml files? So... how can I generate the pojo classes automagically given only the schemafile? I have read the description of the schema-first approach at graphql-java but they also assume to write the pojo-classes by oneself.

thank you

Tetramethyldiarsine answered 23/7, 2018 at 9:21 Comment(1)
V
1

You can use a plugin for your build tool to generate POJOs for GraphQL types/inputs/interfaces/enums/etc and interfaces for queries/mutations/subscriptions. All based on your GraphQL schema.

Link to the project: https://github.com/kobylynskyi/graphql-java-codegen

It has the following plugins for your build tool:

Vinegarette answered 12/9, 2019 at 18:26 Comment(2)
Hi, I tried the gradle plugin. One drawback I see for nested queries, suppose there is a product object with a nested Cost object, and a query for get product by id. The generated stub is for methdo productById(), which will always query the Cost object irrespective of cost being requested. Can we do away with this tight coupling?Madson
Sure. You can create an issue in the following repo with the suggested approach: github.com/kobylynskyi/graphql-java-codegenVinegarette

© 2022 - 2024 — McMap. All rights reserved.