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

org.rapidgraphql.schemabuilder.RapidGraphQLContextBuilder Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
package org.rapidgraphql.schemabuilder;

import graphql.kickstart.execution.context.DefaultGraphQLContextBuilder;
import graphql.kickstart.execution.context.GraphQLKickstartContext;
import graphql.kickstart.servlet.context.GraphQLServletContextBuilder;
import org.dataloader.DataLoaderRegistry;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.websocket.Session;
import jakarta.websocket.server.HandshakeRequest;

import java.util.HashMap;
import java.util.Map;

public class RapidGraphQLContextBuilder extends DefaultGraphQLContextBuilder
        implements GraphQLServletContextBuilder {
    private final DataLoaderRegistryFactory dataLoaderRegistryFactory;

    public RapidGraphQLContextBuilder(DataLoaderRegistryFactory dataLoaderRegistryFactory) {
        this.dataLoaderRegistryFactory = dataLoaderRegistryFactory;
    }


    @Override
    public GraphQLKickstartContext build(HttpServletRequest request, HttpServletResponse response) {
        Map map = new HashMap<>();
        map.put(HttpServletRequest.class, request);
        map.put(HttpServletResponse.class, response);
        return GraphQLKickstartContext.of(buildDataLoaderRegistry(), map);
    }

    @Override
    public GraphQLKickstartContext build(Session session, HandshakeRequest handshakeRequest) {
        Map map = new HashMap<>();
        map.put(Session.class, session);
        map.put(HandshakeRequest.class, handshakeRequest);
        return GraphQLKickstartContext.of(buildDataLoaderRegistry(), map);
    }

    private DataLoaderRegistry buildDataLoaderRegistry() {
        return dataLoaderRegistryFactory.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy