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

Simplify use of DGS Codegen with GraphQlClient #846

Closed
rstoyanchev opened this issue Nov 15, 2023 · 0 comments
Closed

Simplify use of DGS Codegen with GraphQlClient #846

rstoyanchev opened this issue Nov 15, 2023 · 0 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Nov 15, 2023

Given schema:

type Query {
    books: [Book]
}

type Book {
    id: ID
    name: String
}

and DGS codegen generated client request types, it's possible to do this:

GraphQlClient client = HttpGraphQlClient.create(WebClient.create("http://localhost:8080/graphql"));

BooksGraphQLQuery query = new BooksGraphQLQuery();
String document = new GraphQLQueryRequest(query, new BooksProjectionRoot<>().id().name()).serialize();

List<Book> books = client.document(document)
		.retrieve(query.getOperationName())
		.toEntityList(Book.class)
		.block();

We can simplify this further through a DGS Codegen specific GraphQlClient wrapper that prepares request document, so it looks more like this:

HttpGraphQlClient httpGraphQlClient =
		HttpGraphQlClient.create(WebClient.create("http://localhost:8080/graphql"));

DgsCodegenGraphQlClient client = new DgsCodegenGraphQlClient(httpGraphQlClient);

List<Book> books = client.retrieve(new BooksGraphQLQuery(), new BooksProjectionRoot<>().id().name())
		.toEntityList(Book.class)
		.block();

This is only meant to sketch the idea, with the exact details of the API to be worked out.

@rstoyanchev rstoyanchev added the type: enhancement A general enhancement label Nov 15, 2023
@rstoyanchev rstoyanchev added this to the 1.3 Backlog milestone Nov 15, 2023
@rstoyanchev rstoyanchev modified the milestones: 1.3 Backlog, 1.3.0-M1 Dec 8, 2023
@rstoyanchev rstoyanchev self-assigned this Jan 25, 2024
@rstoyanchev rstoyanchev changed the title Simplify use of DGS Codegen with GraphQlClient and GraphQlTester Simplify use of DGS Codegen with GraphQlClient Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant