Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm trying to use the experimental ScheduledDataLoaderRegistry. We need to set up a different dispatch predicate per data loader. Is it possible to have multiple ScheduledDataLoaderRegistry instances, each with different dispatch predicates?
There seems to be only one data loader registry that we can set up with the execution input. Is there another way to have a different dispatch predicate per data loader within the ScheduledDataLoaderRegistry?

ExecutionInput executionInput = newExecutionInput()
        .query(getQuery())
        .dataLoaderRegistry(registry)
        .build();
You must be logged in to vote

Replies: 2 comments · 7 replies

Comment options

in graphql-java - no - there is only 1 dataloader registry used

What do you want multiple for - certain dataloaders get different parameters??

You could write a delegating DataLoaderRegistry that some how finds them from a group of them maybe??

You must be logged in to vote
6 replies
@bbakerman
Comment options

Maye something like

    class DelegatingDataLoaderRegistry extends DataLoaderRegistry {
        private final List<DataLoaderRegistry> registries;

        public DelegatingDataLoaderRegistry(List<DataLoaderRegistry> registries) {
            this.registries = registries;
        }

        @Override
        public List<DataLoader<?, ?>> getDataLoaders() {
            List<DataLoader<?, ?>> loaders = new ArrayList<>(super.getDataLoaders());
            registries.forEach( dlr -> loaders.addAll(dlr.getDataLoaders()));
            return loaders;
        }

        @Override
        public Map<String, DataLoader<?, ?>> getDataLoadersMap() {
            Map<String, DataLoader<?, ?>> loaders = new LinkedHashMap<>(super.getDataLoadersMap());
            registries.forEach( dlr -> loaders.putAll(dlr.getDataLoadersMap()));
            return loaders;
        }

        @Override
        public <K, V> DataLoader<K, V> getDataLoader(String key) {
            DataLoader<K, V> dataLoader = super.getDataLoader(key);
            if (dataLoader == null) {
                for (DataLoaderRegistry registry : registries) {
                    dataLoader = registry.getDataLoader(key);
                    if (dataLoader != null) {
                        return dataLoader;
                    }
                }
            }
            return null;
        }

        @Override
        public Set<String> getKeys() {
            return getDataLoadersMap().keySet();
        }

        @Override
        public void dispatchAll() {
            super.dispatchAll();
            for (DataLoaderRegistry registry : registries) {
                registry.dispatchAll();
            }
        }

        @Override
        public int dispatchAllWithCount() {
            int count = super.dispatchAllWithCount();
            for (DataLoaderRegistry registry : registries) {
                count += registry.dispatchAllWithCount();
            }
            return count;
        }

        @Override
        public int dispatchDepth() {
            int count = super.dispatchDepth();
            for (DataLoaderRegistry registry : registries) {
                count += registry.dispatchDepth();
            }
            return count;
        }

    }

where the main registry is really a list of others ??

This is a rough bit of code - eg should you be alllowed to "register new DL" into this combining one?? Or should computeIfAnsent work or not?

I am not sure - I just whipped this up as an idea

@srinivasankavitha
Comment options

Thanks so much. I think this makes the most sense for our use case. Will try this out. Do you think this would be something worth supporting in the future as part of the java-dataloader? Or is it too specific a use case?

@bbakerman
Comment options

Nah perhaps it would be a good idea

@LeiWangHoward
Comment options

Any specific reason we don't want to support per dataloader dispatch predicate configuration?

Any plan to support this feature, or it's okay to submit community pull request?

@bbakerman
Comment options

This is now supported in 3.2.1

Comment options

See https://github.com/graphql-java/java-dataloader/pull/130/files

You must be logged in to vote
1 reply
@srinivasankavitha
Comment options

This is great, thank you!

Answer selected by dondonz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.