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

fix: ExecutionInput locale is null #1989

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -17,8 +18,13 @@
import org.dataloader.DataLoaderFactory;
import org.dataloader.DataLoaderRegistry;

import graphql.*;
import graphql.ExecutionInput;
import graphql.ExecutionInput.Builder;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.GraphQL;
import graphql.GraphQLError;
import graphql.GraphqlErrorBuilder;
import graphql.analysis.MaxQueryComplexityInstrumentation;
import graphql.analysis.MaxQueryDepthInstrumentation;
import graphql.execution.ExecutionId;
Expand Down Expand Up @@ -151,6 +157,7 @@ public void execute(JsonObject jsonInput, Map<String, Object> context, Execution
// Query
Builder executionBuilder = ExecutionInput.newExecutionInput()
.query(query)
.locale(resolveLocale(context))
.executionId(finalExecutionId);

// Variables
Expand Down Expand Up @@ -195,6 +202,14 @@ public void execute(JsonObject jsonInput, Map<String, Object> context, Execution
}
}

private Locale resolveLocale(Map<String, Object> context) {
Object mayLocale = context.get("locale");
if (mayLocale instanceof Locale) {
return (Locale) mayLocale;
}
return Locale.getDefault();
}

private static void sendError(String errorMessage, ExecutionResponseWriter writer) {
GraphQLError error = GraphqlErrorBuilder
.newError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GraphQLExceptionWhileDataFetching extends ExceptionWhileDataFetchin

public GraphQLExceptionWhileDataFetching(ResultPath path, Throwable exception, SourceLocation sourceLocation) {
super(path, exception, sourceLocation);
this.message = super.getException().getMessage();
this.message = super.getException().getLocalizedMessage();
}

public GraphQLExceptionWhileDataFetching(String message, ResultPath path, Throwable exception,
Expand Down
Loading