spring-graphql icon indicating copy to clipboard operation
spring-graphql copied to clipboard

Code generation from maven/gradle goals?

Open marc06210 opened this issue 4 years ago • 4 comments

is it possible to generate java code (data model and Query, Mutation,... mappings) from the schema with a maven/gradle goal?

marc06210 avatar Oct 04 '21 10:10 marc06210

We don't offer build plugins at the moment. I assume this is about generating model classes and Query builders from a remote GraphQL schema, in order to use those in a GraphQL client?

If this is the case, we're working on a client implementation so we need to tackle #10 first and then consider this issue.

bclozel avatar Oct 06 '21 09:10 bclozel

:+1: to this issue: we want to move away from DGS framework to Spring for Graphql, and we are using some Gradle DGS plugins to generate the client model.

estigma88 avatar Jul 21 '22 19:07 estigma88

This is not blocked anymore, so we need to discuss this as a team.

bclozel avatar Jul 21 '22 20:07 bclozel

Doesn't the code generation make sense also for server?

Once I handwrite the graphql schema, it makes sense to me to generate at least DTOs for it. Is there any reason to not support code generation for server?

From: https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/ Isn't writing

type Book {
  id: ID
  name: String
  pageCount: Int
  author: Author
}

and also

public class Book {

    private String id;
    private String name;
    private int pageCount;
    private String authorId;

    public Book(String id, String name, int pageCount, String authorId) {
        this.id = id;
        this.name = name;
        this.pageCount = pageCount;
        this.authorId = authorId;
    }
    
    public String getId() {
        return id;
    }

    public String getAuthorId() {
        return authorId;
    }
}

kind of duplicate?

jludvice avatar Aug 12 '22 07:08 jludvice

We've discussed this as a team today and we came to the following conclusion: while we think this is a valid use case, we don't feel like this is a top priority for the project now. On the client side, we're working on interface clients to avoid the need for code generation. On the server side, we think that tooling provided by DGS and other libraries should be usable with a Spring for GraphQL project.

We might reconsider this feature for future releases, but for now we would like to focus on highly requested features like multipart, relay/pagination, observability, GraalVM native, nullability support, etc.

If you're still interested in this feature, feel free to upvote the original description. Thanks!

bclozel avatar Sep 22 '22 11:09 bclozel