-
Notifications
You must be signed in to change notification settings - Fork 102
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
Generates data fetcher interface for query types #126
base: master
Are you sure you want to change the base?
Generates data fetcher interface for query types #126
Conversation
Hi, Thanks |
@ilterpehlivan yes, essentially it does, original discussion: Netflix/dgs-framework#234 |
4ed5f96
to
5bb5f5e
Compare
rebased, tests are now passing |
5bb5f5e
to
a927018
Compare
Many things changed since I opened this MR. Should this behaviour be also added to the edit: added in a later commit - the generated interfaces are the same, I thing this code branch only effects data classes, but not data fetcher interfaces |
TODO: resolve issues with the generated annotation edit: fiexed, see next comment public interface ShowsDatafetcher {
@DgsData(
parentType,
field,
)
public fun getShows(titleFilter: String?, dataFetchingEnvironment: DataFetchingEnvironment):
List<Show?>?
}
|
a927018
to
1599deb
Compare
resolved annotation generation issue, also added DgsComponent annotation to this interface @DgsComponent
public interface ShowsDatafetcher {
@DgsData(
parentType = DgsConstants.QUERY.TYPE_NAME,
field = DgsConstants.QUERY.Shows,
)
public fun getShows(titleFilter: String?, dataFetchingEnvironment: DataFetchingEnvironment):
List<Show?>?
}
|
1599deb
to
d3fc878
Compare
added one more thing, again, oversight from my part: input argument annotation @DgsComponent
public interface ShowsDatafetcher {
@DgsData(
parentType = DgsConstants.QUERY.TYPE_NAME,
field = DgsConstants.QUERY.Shows,
)
public fun getShows(@InputArgument("titleFilter") titleFilter: String?,
dataFetchingEnvironment: DataFetchingEnvironment): List<Show?>?
} |
changed datafetcher postfix to query, also added generator for mutation and subscription - these are based on https://github.com/Netflix/dgs-examples-kotlin @DgsComponent
public interface ShowsQuery {
@DgsData(
parentType = DgsConstants.QUERY.TYPE_NAME,
field = DgsConstants.QUERY.Shows,
)
public fun shows(@InputArgument(DgsConstants.QUERY.SHOWS_INPUT_ARGUMENT.TitleFilter)
titleFilter: String?, dataFetchingEnvironment: DataFetchingEnvironment): List<Show?>?
}
@DgsComponent
public interface AddArtworkMutation {
@DgsData(
parentType = DgsConstants.MUTATION.TYPE_NAME,
field = DgsConstants.MUTATION.AddArtwork,
)
public fun addArtwork(
@InputArgument(DgsConstants.MUTATION.ADDARTWORK_INPUT_ARGUMENT.ShowId) showId: Int,
@InputArgument(DgsConstants.MUTATION.ADDARTWORK_INPUT_ARGUMENT.Upload) upload: MultipartFile,
dataFetchingEnvironment: DataFetchingEnvironment,
): List<Image?>
}
@DgsComponent
public interface AddReviewMutation {
@DgsData(
parentType = DgsConstants.MUTATION.TYPE_NAME,
field = DgsConstants.MUTATION.AddReview,
)
public fun addReview(@InputArgument(DgsConstants.MUTATION.ADDREVIEW_INPUT_ARGUMENT.Review)
review: SubmittedReview?, dataFetchingEnvironment: DataFetchingEnvironment): List<Review?>?
}
@DgsComponent
public interface ReviewAddedSubscription {
@DgsData(
parentType = DgsConstants.SUBSCRIPTION.TYPE_NAME,
field = DgsConstants.SUBSCRIPTION.ReviewAdded,
)
public fun reviewAdded(@InputArgument(DgsConstants.SUBSCRIPTION.REVIEWADDED_INPUT_ARGUMENT.ShowId)
showId: Int, dataFetchingEnvironment: DataFetchingEnvironment): Publisher<Review?>
}
|
…nd generateDataFetcherInterfaces is true
also addedd datafetcher interface generation to kotlin2 code branch it would generate the same interface files as the other branch - the difference in this branch is that instead of generating non-nullable fields on data classes, it generates a "supplier". the reason for this is when the client doesn't requests a non-nullable field, the server would still invoke the data fetcher for it, otherwise it would run into a initialization filter. this behaviour doesn't affect the data fetcher interfaces |
@paulbakker @iuliiasobolevska @srinivasankavitha this feature request adds new functionality without modifying existing behaviour. wdyt, is it something that you can merge into mainline? Short description of the feature below: I've added a new configuration option to the gradle plugin, This enables a workflow descirbed in Netflix/dgs-framework#234 |
The Java generator has an option to generate example data fetchers that can be copied into the codebase and extended as needed, but the kotlin generator has no such option.
This PR implements example data fetcher generator for kotlin with a twist: instead of generating a a class with TODO bodies, it generates an interface, for now.
This is the first in a series of PRs that would add an option similar to OpenAPI kotlin-spring generator
interfaceOnly
option.Interfaces generated by this way would only be usable if the example output directory is set to the generated code directory. However, the generated interfaces would not be useable until Netflix/dgs-framework#320 is resolved. - update this is now merged
The enables the development of schemas in a separate repository. Automation would use this generator to generate data classes for types and interfaces for data fetchers and mutations that server component must implement. The generated sources would be packaged and published as a jar. Added a configuration flag
generateDataFetcherInterfaces
to make this behaviour opt-in.edit: elaborates scope, links to PR in dsg-framework, new config param.