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

Add trivial field to DgsData / DgsQuery annotations for marking trivial data fetcher methods #1955

Merged
merged 3 commits into from
Jul 16, 2024

Conversation

kilink
Copy link
Member

@kilink kilink commented Jul 8, 2024

Add ability to mark data fetcher methods as trivial

Add a "trivial" boolean field to DgsData and DgsQuery annotations which allows signaling to DGS
that the generated DataFetcher should implement TrivialDataFetcher. This can benefit data fetcher
methods that don't do any I/O, since they can be handled specially by instrumentation.

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface Trivial { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DgsTrivial?

I'm torn on this, as I never liked the prefix, but it's on nearly all of the interfaces. And with the spring-graphql integration, I feel like the inconsistency might add some initial readability confusion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I understand that concern, I ended up revisiting just adding a new field to the existing annotations based on Paul's feedback, and was able to make that work, so I'm scrapping this new annotation anyway.

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface Trivial { }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered making it a new argument for @DgsData? As long as it has a default value, that would be backward compatible as well I think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall considering that approach, but I couldn't think of a clean way to make DgsQuery work, although I guess I could add it to DgsQuery as well and annotate the field with @AliasFor to make that work. Having multiple DgsData annotations via @DgsData.List is also another thing I'd have to make sure works correctly. I can experiment with that and see if it works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulbakker okay, I've updated the PR to just use fields on the existing DgsData / DgsQuery annotations, and added test cases for the various scenarios.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! I think I prefer this approach, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I prefer this over adding a new annotation.

@@ -39,16 +43,31 @@ class MethodDataFetcherFactory(
private val resolvers = ArgumentResolverComposite(argumentResolvers)

fun createDataFetcher(bean: Any, method: Method): DataFetcher<Any?> {
if (isTrivial(method) || isTrivial(bean.javaClass)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should allow this on class level. It's probably unlikely that it's adding a lot of convenience, while it would be easy to have an unintended side-effect on datafetchers added later to an existing class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can just remove it for now then.

Add a "trivial" boolean field to DgsData and DgsQuery annotations which allows signaling to DGS
that the generated DataFetcher should implement TrivialDataFetcher. This can benefit data fetcher
methods that don't do any I/O, since they can be handled specially by instrumentation.
@kilink kilink changed the title Add Trivial annotation for marking trivial data fetcher methods Add trivial field to DgsData / DgsQuery annotations for marking trivial data fetcher methods Jul 9, 2024
@paulbakker paulbakker self-requested a review July 9, 2024 19:19
Copy link
Contributor

@srinivasankavitha srinivasankavitha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me.

@@ -38,17 +43,44 @@ class MethodDataFetcherFactory(

private val resolvers = ArgumentResolverComposite(argumentResolvers)

fun createDataFetcher(bean: Any, method: Method): DataFetcher<Any?> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a test case with a trivial data fetcher usage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had written tests but forgot to check them in. I've updated the PR.

@kilink kilink merged commit 59cbea4 into master Jul 16, 2024
3 checks passed
@kilink kilink deleted the trivial-data-fetcher branch July 16, 2024 18:14
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.

4 participants