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

Feature: generate datafetcher interfaces for java and kotlin via config #329

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mcarleio
Copy link

Add new configuration generateDataFetchersAsInterfaces and generation code for Java and Kotlin to generate data fetchers as interfaces (instead of generating data fetchers with some default example implementation).

❗ Based on #327

@mcarleio
Copy link
Author

mcarleio commented Feb 16, 2022

The following will show the usage on a small example:

Assume the following schema:

type Query {
  people: [Person]
}

type Person {
  name: String
  partner: Person
}

This will generate the following two interfaces:

public interface QueryDataFetcher {
  @DgsQuery(
      field = "people"
  )
  List<Person> people(DgsDataFetchingEnvironment dataFetchingEnvironment);
}

public interface PersonDataFetcher {
  @DgsData(
      field = "partner",
      parentType = "Person"
  )
  CompletableFuture<Person> partner(DgsDataFetchingEnvironment dataFetchingEnvironment);
}

The only open step is to implement these interfaces and add the @DgsComponent annotation:

@DgsComponent
public class QueryDataFetcherImpl implements QueryDataFetcher {
    @Override
    public List<Person> people(DgsDataFetchingEnvironment dataFetchingEnvironment) {
        // load persons e.g. from DB
    }
}

@DgsComponent
public class PersonDataFetcherImpl implements PersonDataFetcher {
    @Override
    public CompletableFuture<Person> partner(DgsDataFetchingEnvironment dataFetchingEnvironment) {
        // implement as needed (e.g. make a DB call, use a dataloader, ...)
    }
}

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

Successfully merging this pull request may close these issues.

1 participant