Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
jbellenger committed Apr 2, 2024
2 parents 0dac307 + c49da41 commit b906880
Show file tree
Hide file tree
Showing 27 changed files with 282 additions and 203 deletions.
2 changes: 1 addition & 1 deletion agent-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

dependencies {
implementation(rootProject)
implementation("net.bytebuddy:byte-buddy-agent:1.14.12")
implementation("net.bytebuddy:byte-buddy-agent:1.14.13")

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
2 changes: 1 addition & 1 deletion agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

dependencies {
implementation("net.bytebuddy:byte-buddy:1.14.12")
implementation("net.bytebuddy:byte-buddy:1.14.13")
// graphql-java itself
implementation(rootProject)
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/graphql/scalar/GraphqlBooleanCoercing.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ private Boolean serializeImpl(@NotNull Object input, @NotNull Locale locale) {

@NotNull
private Boolean parseValueImpl(@NotNull Object input, @NotNull Locale locale) {
Boolean result = convertImpl(input);
if (result == null) {
if (!(input instanceof Boolean)) {
throw new CoercingParseValueException(
i18nMsg(locale, "Boolean.notBoolean", typeName(input))
i18nMsg(locale, "Boolean.unexpectedRawValueType", typeName(input))
);
}
return result;
return (Boolean) input;
}

private static boolean parseLiteralImpl(@NotNull Object input, @NotNull Locale locale) {
Expand Down Expand Up @@ -129,7 +128,7 @@ public Boolean parseLiteral(@NotNull Object input) {

@Override
@Deprecated
public Value valueToLiteral(@NotNull Object input) {
public @NotNull Value<?> valueToLiteral(@NotNull Object input) {
return valueToLiteralImpl(input, Locale.getDefault());
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/graphql/scalar/GraphqlFloatCoercing.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ private Double serialiseImpl(Object input, @NotNull Locale locale) {

@NotNull
private Double parseValueImpl(@NotNull Object input, @NotNull Locale locale) {
if (!(input instanceof Number)) {
throw new CoercingParseValueException(
i18nMsg(locale, "Float.unexpectedRawValueType", typeName(input))
);
}

Double result = convertImpl(input);
if (result == null) {
throw new CoercingParseValueException(
Expand Down
35 changes: 32 additions & 3 deletions src/main/java/graphql/scalar/GraphqlIntCoercing.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,44 @@ private Integer serialiseImpl(Object input, @NotNull Locale locale) {

@NotNull
private Integer parseValueImpl(@NotNull Object input, @NotNull Locale locale) {
Integer result = convertImpl(input);
if (!(input instanceof Number)) {
throw new CoercingParseValueException(
i18nMsg(locale, "Int.notInt", typeName(input))
);
}

if (input instanceof Integer) {
return (Integer) input;
}

BigInteger result = convertParseValueImpl(input);
if (result == null) {
throw new CoercingParseValueException(
i18nMsg(locale, "Int.notInt", typeName(input))
);
}
if (result.compareTo(INT_MIN) < 0 || result.compareTo(INT_MAX) > 0) {
throw new CoercingParseValueException(
i18nMsg(locale, "Int.outsideRange", result.toString())
);
}
return result.intValueExact();
}

return result;
private BigInteger convertParseValueImpl(Object input) {
BigDecimal value;
try {
value = new BigDecimal(input.toString());
} catch (NumberFormatException e) {
return null;
}

try {
return value.toBigIntegerExact();
} catch (ArithmeticException e) {
// Exception if number has non-zero fractional part
return null;
}
}

private static int parseLiteralImpl(Object input, @NotNull Locale locale) {
Expand Down Expand Up @@ -134,7 +163,7 @@ public Integer parseLiteral(@NotNull Object input) {

@Override
@Deprecated
public Value valueToLiteral(@NotNull Object input) {
public @NotNull Value<?> valueToLiteral(@NotNull Object input) {
return valueToLiteralImpl(input, Locale.getDefault());
}

Expand Down
15 changes: 12 additions & 3 deletions src/main/java/graphql/scalar/GraphqlStringCoercing.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ private String toStringImpl(Object input) {
return String.valueOf(input);
}

private String parseValueImpl(@NotNull Object input, @NotNull Locale locale) {
if (!(input instanceof String)) {
throw new CoercingParseValueException(
i18nMsg(locale, "String.unexpectedRawValueType", typeName(input))
);
}
return (String) input;
}

private String parseLiteralImpl(@NotNull Object input, Locale locale) {
if (!(input instanceof StringValue)) {
throw new CoercingParseLiteralException(
Expand Down Expand Up @@ -55,12 +64,12 @@ public String serialize(@NotNull Object dataFetcherResult) {
@Override
@Deprecated
public String parseValue(@NotNull Object input) {
return toStringImpl(input);
return parseValueImpl(input, Locale.getDefault());
}

@Override
public String parseValue(@NotNull Object input, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingParseValueException {
return toStringImpl(input);
return parseValueImpl(input, locale);
}

@Override
Expand All @@ -76,7 +85,7 @@ public String parseLiteral(@NotNull Object input) {

@Override
@Deprecated
public Value valueToLiteral(@NotNull Object input) {
public @NotNull Value<?> valueToLiteral(@NotNull Object input) {
return valueToLiteralImpl(input);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/graphql/schema/GraphQLDirective.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.function.Consumer;
import java.util.function.UnaryOperator;

import static graphql.Assert.assertNotEmpty;
import static graphql.Assert.assertNotNull;
import static graphql.Assert.assertValidName;
import static graphql.introspection.Introspection.DirectiveLocation;
Expand Down Expand Up @@ -52,6 +53,7 @@ private GraphQLDirective(String name,
DirectiveDefinition definition) {
assertValidName(name);
assertNotNull(arguments, () -> "arguments can't be null");
assertNotEmpty(locations, () -> "locations can't be empty");
this.name = name;
this.description = description;
this.repeatable = repeatable;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/i18n/Scalars.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ ID.unexpectedAstType=Expected an AST type of ''IntValue'' or ''StringValue'' but
#
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}''
Float.unexpectedRawValueType=Expected a Number input, but it was a ''{0}''
#
Boolean.notBoolean=Expected a value that can be converted to type ''Boolean'' but it was a ''{0}''
Boolean.unexpectedAstType=Expected an AST type of ''BooleanValue'' but it was a ''{0}''
Boolean.unexpectedRawValueType=Expected a Boolean input, but it was a ''{0}''
#
String.unexpectedRawValueType=Expected a String input, but it was a ''{0}''
4 changes: 4 additions & 0 deletions src/main/resources/i18n/Scalars_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ ID.unexpectedAstType=Erwartet wurde ein AST type von ''IntValue'' oder ''StringV
#
Float.notFloat=Erwartet wurde ein Wert, der in den Typ ''Float'' konvertiert werden kann, aber es war ein ''{0}''
Float.unexpectedAstType=Erwartet wurde ein AST type von ''IntValue'' oder ''FloatValue'', aber es war ein ''{0}''
Float.unexpectedRawValueType=Erwartet wurde eine Number-Eingabe, aber es war ein ''{0}''
#
Boolean.notBoolean=Erwartet wurde ein Wert, der in den Typ ''Boolean'' konvertiert werden kann, aber es war ein ''{0}''
Boolean.unexpectedAstType=Erwartet wurde ein AST type ''BooleanValue'', aber es war ein ''{0}''
Boolean.unexpectedRawValueType=Erwartet wurde eine Boolean-Eingabe, aber es war ein ''{0}''
#
String.unexpectedRawValueType=Erwartet wurde eine String-Eingabe, aber es war ein ''{0}''
7 changes: 7 additions & 0 deletions src/main/resources/i18n/Scalars_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ ID.unexpectedAstType=Verwacht werd een AST-type ''IntValue'' of ''StringValue'',
#
Float.notFloat=Verwacht werd een waarde die in ''Float'' veranderd kon worden, maar het was een ''{0}''
Float.unexpectedAstType=Verwacht werd een AST-type ''IntValue'' of ''FloatValue'', maar het was een ''{0}''
# TODO: To be translated into Dutch
Float.unexpectedRawValueType=Expected a Number input, but it was a ''{0}''
#
Boolean.notBoolean=Verwacht werd een waarde die in ''Boolean'' veranderd kon worden, maar het was een ''{0}''
Boolean.unexpectedAstType=Verwacht werd een AST-type ''BooleanValue'', maar het was een ''{0}''
# TODO: To be translated into Dutch
Boolean.unexpectedRawValueType=Expected a Boolean input, but it was a ''{0}''
#
# TODO: To be translated into Dutch
String.unexpectedRawValueType=Expected a String input, but it was a ''{0}''
88 changes: 39 additions & 49 deletions src/test/groovy/graphql/ScalarsBooleanTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ class ScalarsBooleanTest extends Specification {
Scalars.GraphQLBoolean.getCoercing().serialize(value, GraphQLContext.default, Locale.default) == result

where:
value | result
true | true
"false" | false
"true" | true
"True" | true
0 | false
1 | true
-1 | true
new Long(42345784398534785l) | true
new Double(42.3) | true
new Float(42.3) | true
Integer.MAX_VALUE + 1l | true
Integer.MIN_VALUE - 1l | true
value | result
true | true
"false" | false
"true" | true
"True" | true
0 | false
1 | true
-1 | true
Long.valueOf(42345784398534785l) | true
Double.valueOf(42.3) | true
Float.valueOf(42.3) | true
Integer.MAX_VALUE + 1l | true
Integer.MIN_VALUE - 1l | true
}

@Unroll
Expand All @@ -76,19 +76,19 @@ class ScalarsBooleanTest extends Specification {
Scalars.GraphQLBoolean.getCoercing().serialize(value) == result // Retain deprecated method for test coverage

where:
value | result
true | true
"false" | false
"true" | true
"True" | true
0 | false
1 | true
-1 | true
new Long(42345784398534785l) | true
new Double(42.3) | true
new Float(42.3) | true
Integer.MAX_VALUE + 1l | true
Integer.MIN_VALUE - 1l | true
value | result
true | true
"false" | false
"true" | true
"True" | true
0 | false
1 | true
-1 | true
Long.valueOf(42345784398534785l) | true
Double.valueOf(42.3) | true
Float.valueOf(42.3) | true
Integer.MAX_VALUE + 1l | true
Integer.MIN_VALUE - 1l | true
}

@Unroll
Expand Down Expand Up @@ -131,27 +131,6 @@ class ScalarsBooleanTest extends Specification {
false | false
}

@Unroll
def "parseValue parses non-Boolean input #value"() {
expect:
Scalars.GraphQLBoolean.getCoercing().parseValue(value, GraphQLContext.default, Locale.default) == result

where:
value | result
true | true
"false" | false
"true" | true
"True" | true
0 | false
1 | true
-1 | true
new Long(42345784398534785l) | true
new Double(42.3) | true
new Float(42.3) | true
Integer.MAX_VALUE + 1l | true
Integer.MIN_VALUE - 1l | true
}

@Unroll
def "parseValue throws exception for invalid input #value"() {
when:
Expand All @@ -160,8 +139,19 @@ class ScalarsBooleanTest extends Specification {
thrown(CoercingParseValueException)

where:
value | _
new Object() | _
value | _
new Object() | _
"false" | _
"true" | _
"True" | _
0 | _
1 | _
-1 | _
Long.valueOf(42345784398534785l) | _
Double.valueOf(42.3) | _
Float.valueOf(42.3) | _
Integer.MAX_VALUE + 1l | _
Integer.MIN_VALUE - 1l | _
}

}
Loading

0 comments on commit b906880

Please sign in to comment.