Adding Locale to Coercing and hence ValueResolver#2912
Conversation
| /** | ||
| * Allows you to build a new coercing environment | ||
| * | ||
| * @param <T> for two |
| ValueMode valueMode) { | ||
| GraphQLInputObjectType inputObjectType, | ||
| Object inputValue, | ||
| ValueMode valueMode, Locale locale) { |
There was a problem hiding this comment.
Super nit: add new line before Locale
| List<VariableDefinition> variableDefinitions, | ||
| RawVariables rawVariables) { | ||
| List<VariableDefinition> variableDefinitions, | ||
| RawVariables rawVariables, Locale locale) { |
There was a problem hiding this comment.
Super nit: add new line before Locale
| GraphQLType graphQLType, | ||
| Object value) throws NonNullableValueCoercedAsNullException, CoercingParseValueException { | ||
| GraphQLType graphQLType, | ||
| Object value, Locale locale) throws NonNullableValueCoercedAsNullException, CoercingParseValueException { |
There was a problem hiding this comment.
Super nit: add new line before Locale
| * | ||
| * @param <T> for two | ||
| */ | ||
| public interface CoercingEnvironment<T> { |
There was a problem hiding this comment.
Feedback - kill it - its not an overhead we want to add in terms of object allocation
…coercing # Conflicts: # src/main/java/graphql/normalized/ExecutableNormalizedOperationFactory.java
| CoercedVariables.of(variables), | ||
| GraphQLContext.getDefault(), | ||
| Locale.getDefault()); | ||
| QueryVisitorFieldEnvironment environment = new QueryVisitorFieldEnvironmentImpl(isTypeNameIntrospectionField, |
There was a problem hiding this comment.
This entry point come not from a graphql request and hence uses a default graphql context and default locale. Perhaps in some future change these are passed in.
| this.roots = singletonList(getOperationResult.operationDefinition); | ||
| this.rootParentType = getRootTypeFromOperation(getOperationResult.operationDefinition); | ||
| this.coercedVariables = ValuesResolver.coerceVariableValues(schema, variableDefinitions, rawVariables); | ||
| this.coercedVariables = ValuesResolver.coerceVariableValues(schema, variableDefinitions, rawVariables, GraphQLContext.getDefault(), Locale.getDefault()); |
There was a problem hiding this comment.
This entry point come not from a graphql request and hence uses a default graphql context and default locale. Perhaps in some future change these are passed in.
| Directive foundDirective = NodeUtil.findNodeByName(directives, directiveName); | ||
| if (foundDirective != null) { | ||
| Map<String, Object> argumentValues = ValuesResolver.getArgumentValues(SkipDirective.getArguments(), foundDirective.getArguments(), CoercedVariables.of(variables)); | ||
| Map<String, Object> argumentValues = ValuesResolver.getArgumentValues(SkipDirective.getArguments(), foundDirective.getArguments(), CoercedVariables.of(variables), GraphQLContext.getDefault(), Locale.getDefault()); |
There was a problem hiding this comment.
This entry point come not from a graphql request and hence uses a default graphql context and default locale. Perhaps in some future change these are passed in.
| CoercedVariables coercedVariables; | ||
| try { | ||
| coercedVariables = ValuesResolver.coerceVariableValues(graphQLSchema, variableDefinitions, inputVariables); | ||
| coercedVariables = ValuesResolver.coerceVariableValues(graphQLSchema, variableDefinitions, inputVariables, executionInput.getGraphQLContext(), executionInput.getLocale()); |
There was a problem hiding this comment.
context and locale take from ExecutionInput
| } | ||
| return serialized == null; | ||
| } | ||
| } |
|
|
||
| protected Object serializeScalarValue(Object toAnalyze, GraphQLScalarType scalarType) throws CoercingSerializeException { | ||
| return scalarType.getCoercing().serialize(toAnalyze); | ||
| return scalarType.getCoercing().serialize(toAnalyze, GraphQLContext.getDefault(), Locale.getDefault()); |
There was a problem hiding this comment.
code will die - here only to compile
| */ | ||
| public enum BundleType { | ||
| Parsing, | ||
| Scalars, |
| private static String printDefaultValue(InputValueWithState inputValueWithState, GraphQLInputType type) { | ||
| return AstPrinter.printAst(ValuesResolver.valueToLiteral(DEFAULT_FIELD_VISIBILITY, inputValueWithState, type)); | ||
| private static String printDefaultValue(InputValueWithState inputValueWithState, GraphQLInputType type, GraphQLContext graphQLContext, Locale locale) { | ||
| return AstPrinter.printAst(ValuesResolver.valueToLiteral(inputValueWithState, type, graphQLContext, locale)); |
There was a problem hiding this comment.
The method defaults this. Used a better method
…coercing # Conflicts: # src/main/java/graphql/execution/nextgen/ExecutionHelper.java # src/main/java/graphql/execution/nextgen/FetchedValueAnalyzer.java # src/main/java/graphql/execution/nextgen/ValueFetcher.java # src/main/java/graphql/schema/idl/FetchSchemaDirectiveWiring.java
| Int.notInt=Expected a value that can be converted to type 'Int' but it was a ''{0}'' | ||
| # | ||
| ID.unexpectedAstType=Expected an AST type of ''IntValue'' or ''StringValue'' but it was a ''{0}''. | ||
| ID.notId=Expected a value that can be converted to type 'ID' but it was a ''{0}'' |
There was a problem hiding this comment.
Nit: could remove the single quotes around 'ID', they won't be rendered
| ID.unexpectedAstType=Expected an AST type of ''IntValue'' or ''StringValue'' but it was a ''{0}''. | ||
| ID.notId=Expected a value that can be converted to type 'ID' but it was a ''{0}'' | ||
| # | ||
| Float.notFloat=Expected a value that can be converted to type 'Float' but it was a ''{0}'' |
There was a problem hiding this comment.
Nit: could remove the single quotes around 'Float', they won't be rendered
| Float.notFloat=Expected a value that can be converted to type 'Float' but it was a ''{0}'' | ||
| Float.unexpectedAstType=Expected an AST type of ''IntValue'' or ''FloatValue'' but it was a ''{0}''. | ||
| # | ||
| Boolean.notBoolean=Expected a value that can be converted to type 'Boolean' but it was a ''{0}'' |
There was a problem hiding this comment.
Nit: could remove the single quotes around 'Boolean', they won't be rendered
| * @param graphQLContext the graphql context in place | ||
| * @param locale the locale to use | ||
| * | ||
| * @return a parsed value which is never null |
There was a problem hiding this comment.
Since this method doesn't carry the @NotNull return annotation anymore, should this comment be updated?
There was a problem hiding this comment.
Thanks, that's a good catch. I'll fix it up
We would like to support Locale when coer-ercing values or parsing document text. So we need that passed in.
This has chosen to pass in a
GraphQLContextand aLocaleto a scalarCoercingso that :Localecan be presentThere are stacks of time where need to use ValueResolver and its methods to resolve values. We need a defaulted locale here and default GraphqlContext to make this work.
The ValueResolver has been substantially re-arranged - none of its logic has changed but the graphql context and locale have been passed on through it.
The class was 1000 lines long. Why too much code in it.
I have split it into 2 - one with the legacy value code into its own class (and then accessed via the ValueResolver) and one with code for value conversions (external to literal etc...)
But the code itself really has not changed. The tests show that - only graphql context and locale have been added
Originally I put the Parser code here (passing in Locale to it) in this PR but it was too big - this is plenty big enough already - so I will make another PR for that