Skip to content
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

io.leangen.graphql.spqr.spring.web.GraphQLController should be fixed to treat variables as optional parameter #333

Closed
slavap opened this issue Jan 3, 2020 · 1 comment

Comments

@slavap
Copy link

slavap commented Jan 3, 2020

In executeJsonPost()

Map<String, Object> variables = requestParams.getVariables() == null ? requestBody.getVariables() : requestParams.getVariables();
// the following line must be added:
if (variables == null) variables = new HashMap<>();

Without this fix for example Voyager tool is not working, and I have to register custom GraphQLServletExecutor like this one:

public class SafeGraphQLExecutor extends DefaultGraphQLExecutor {

    public SafeGraphQLExecutor(ServletContextFactory contextFactory,
                               DataLoaderRegistryFactory dataLoaderRegistryFactory) {
        super(contextFactory, dataLoaderRegistryFactory);
    }

    @Override
    public Map<String, Object> execute(GraphQL graphQL, GraphQLRequest graphQLRequest, NativeWebRequest nativeRequest) {
        final GraphQLRequest req;
        if (graphQLRequest.getVariables() == null) {
            String query = graphQLRequest.getQuery();
            String operationName = graphQLRequest.getOperationName();
            Map<String, Object> variables = new HashMap<>();
            req = new GraphQLRequest(query, operationName, variables);

        } else {
            req = graphQLRequest;
        }
        return super.execute(graphQL, req, nativeRequest);
    }

}
@kaqqao
Copy link
Member

kaqqao commented Jan 11, 2020

Wrong project. Duplicate issue. Will be fixed soon.

@kaqqao kaqqao closed this as completed Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants