All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.demographql.helloworld.ChatQuery Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
package org.demographql.helloworld;

import graphql.kickstart.tools.GraphQLQueryResolver;
import graphql.schema.DataFetchingEnvironment;
import org.dataloader.DataLoader;
import org.rapidgraphql.annotations.DataLoaderMethod;
import org.rapidgraphql.directives.GraphQLDataLoader;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Component
public class ChatQuery implements GraphQLQueryResolver, GraphQLDataLoader {
    public CompletableFuture> chat(int numMessages, DataFetchingEnvironment environment) {
        DataLoader dataLoader = environment.getDataLoader("chat");
        return dataLoader.loadMany(IntStream.range(1, numMessages+1).mapToObj(String::valueOf).collect(Collectors.toList()));
    }

    @DataLoaderMethod("chat")
    public List loadChatMessages(List messages) {
        return messages.stream()
                .map(msg -> Chat.builder().youSaid(msg).iSay("Got it " + msg).build())
                .collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy