Skip to content

graphql.kickstart.servlet.context.DefaultGraphQLServletContext cannot be cast to class GraphqlCustomContext #351

@rituja99

Description

@rituja99

I m trying to create a custom context as given below:
@publicapi
@threadsafe
@SuppressWarnings("unchecked")
public class GraphqlCustomContext implements GraphQLServletContext {

private final ConcurrentMap<Object, Object> map;

private GraphqlCustomContext(ConcurrentMap<Object, Object> map){
    this.map = map;
}

@Override
public Optional<Subject> getSubject()
{
    return Optional.empty();
}

@Override
@NonNull
public DataLoaderRegistry getDataLoaderRegistry()
{
  return null;
}

@Override
public List<Part> getFileParts(){
  return null;
}

@Override
public Map<String, List<Part>> getParts(){
    return null;
}

@Override
public HttpServletRequest getHttpServletRequest(){
    return null;
}

@Override
public HttpServletResponse getHttpServletResponse(){
    return null;
}

public void put(Object key, Object value) {
    this.map.put(Assert.assertNotNull(key), Assert.assertNotNull(value));
}

public <T> T get(Object key) {
    return (T) this.map.get(Assert.assertNotNull(key));
}

}

I am getting this error
2021-05-24 14:17:24 [https-jsse-nio-8443-exec-4] WARN n.g.e.SimpleDataFetcherExceptionHandler - Exception while fetching data (/getLatestLedgerTransactions) : class graphql.kickstart.servlet.context.DefaultGraphQLServletContext cannot be cast to class com.gs.txb.dataplatform.graphql.configuration.GraphqlCustomContext (graphql.kickstart.servlet.context.DefaultGraphQLServletContext and com.gs.txb.dataplatform.graphql.configuration.GraphqlCustomContext are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @153f5a29)

For this line
GraphqlCustomContext context = (GraphqlCustomContext) env.getContext();
context.put("source",FAST_STORE);

I need to pass fields from parent to child data fetcher. In older version of graphql-java, we could use env.getExecutionContext().getVariables().put("source,FAST_STORE)
How can I do this in graphql-java-kickstart, apart from creating custom context?
Any Suggestions? @oliemansm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions