graphql.kickstart.servlet.context.DefaultGraphQLServletContext cannot be cast to class GraphqlCustomContext
rituja99 opened this issue · 1 comments
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
You need to provide a custom context builder if you want to be able to use a custom context. See this sample how you can provide a custom context builder: https://github.com/graphql-java-kickstart/samples/blob/master/request-scoped-dataloader/src/main/java/graphql/servlet/examples/dataloader/requestscope/CustomGraphQLContextBuilder.java.