Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rituja99 opened this issue May 24, 2021 · 1 comment

Comments

@rituja99
Copy link

rituja99 commented May 24, 2021

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

@oliemansm
Copy link
Member

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.

@graphql-java-kickstart graphql-java-kickstart locked and limited conversation to collaborators Aug 19, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants