Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/graphql/schema/SingletonPropertyDataFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ public class SingletonPropertyDataFetcher<T> implements LightDataFetcher<T> {

private static final SingletonPropertyDataFetcher<Object> SINGLETON_FETCHER = new SingletonPropertyDataFetcher<>();

private static final DataFetcherFactory<?> SINGLETON_FETCHER_FACTORY = environment -> SINGLETON_FETCHER;
private static final DataFetcherFactory<?> SINGLETON_FETCHER_FACTORY = new DataFetcherFactory<Object>() {
@SuppressWarnings("deprecation")
@Override
public DataFetcher<Object> get(DataFetcherFactoryEnvironment environment) {
return SINGLETON_FETCHER;
}

@Override
public DataFetcher<Object> get(GraphQLFieldDefinition fieldDefinition) {
return SINGLETON_FETCHER;
}
};
Copy link
Member Author

Choose a reason for hiding this comment

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

because I didnt override the default public DataFetcher<Object> get(GraphQLFieldDefinition fieldDefinition) then it returned null and hence it went to the older more heavy weight object and a DataFetcherFactoryEnvironment needed to be allocated.

This now means that no DataFetcherFactoryEnvironment objects are allocated for property fetchers

Copy link
Member Author

@bbakerman bbakerman Apr 29, 2025

Choose a reason for hiding this comment

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

I cant unit test this - its not observable - but profiling shows it to be working!

Copy link
Member

Choose a reason for hiding this comment

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

Nice you could verify via profiling


/**
* This returns the same singleton {@link LightDataFetcher} that fetches property values
Expand Down
Loading