Skip to content

Commit 8e19827

Browse files
authored
Merge pull request #43 from graphql-java/update-to-graphql-java-17x
Updating to graphql-java 17.x and fixing the class constructors
2 parents f4f9cb9 + e179019 commit 8e19827

39 files changed

+1036
-604
lines changed

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import java.text.SimpleDateFormat
33

44
plugins {
55
id 'java'
6+
id 'groovy'
67
id 'java-library'
78
id 'maven'
89
id 'maven-publish'
@@ -39,10 +40,11 @@ repositories {
3940

4041

4142
dependencies {
42-
compile "com.graphql-java:graphql-java:16.1"
43+
compile "com.graphql-java:graphql-java:0.0.0-2021-06-27T12-22-33-cd2bab76"
44+
45+
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
46+
testImplementation('org.codehaus.groovy:groovy:2.5.13')
4347

44-
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
45-
testCompile 'org.codehaus.groovy:groovy-all:2.4.13'
4648
}
4749

4850
task sourcesJar(type: Jar, dependsOn: classes) {

src/main/java/graphql/scalars/ExtendedScalars.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ExtendedScalars {
3939
* @see java.time.OffsetDateTime
4040
* @see java.time.ZonedDateTime
4141
*/
42-
public static GraphQLScalarType DateTime = new DateTimeScalar();
42+
public static GraphQLScalarType DateTime = DateTimeScalar.INSTANCE;
4343

4444
/**
4545
* An RFC-3339 compliant date scalar that accepts string values like `1996-12-19` and produces
@@ -52,7 +52,7 @@ public class ExtendedScalars {
5252
*
5353
* @see java.time.LocalDate
5454
*/
55-
public static GraphQLScalarType Date = new DateScalar();
55+
public static GraphQLScalarType Date = DateScalar.INSTANCE;
5656
/**
5757
* An RFC-3339 compliant time scalar that accepts string values like `6:39:57-08:00` and produces
5858
* `java.time.OffsetTime` objects at runtime.
@@ -64,7 +64,7 @@ public class ExtendedScalars {
6464
*
6565
* @see java.time.OffsetTime
6666
*/
67-
public static GraphQLScalarType Time = new TimeScalar();
67+
public static GraphQLScalarType Time = TimeScalar.INSTANCE;
6868

6969
/**
7070
* An object scalar allows you to have a multi level data value without defining it in the graphql schema.
@@ -89,7 +89,7 @@ public class ExtendedScalars {
8989
*
9090
* @see #Json
9191
*/
92-
public static GraphQLScalarType Object = new ObjectScalar();
92+
public static GraphQLScalarType Object = ObjectScalar.INSTANCE;
9393

9494
/**
9595
* A synonym class for the {@link #Object} scalar, since some people prefer their SDL to look like the following :
@@ -106,68 +106,68 @@ public class ExtendedScalars {
106106
*
107107
* @see graphql.scalars.ExtendedScalars#Object
108108
*/
109-
public static GraphQLScalarType Json = new JsonScalar();
109+
public static GraphQLScalarType Json = JsonScalar.INSTANCE;
110110

111111
/**
112112
* A URL scalar that accepts URL strings and produces {@link java.net.URL} objects at runtime
113113
*/
114-
public static GraphQLScalarType Url = new UrlScalar();
114+
public static GraphQLScalarType Url = UrlScalar.INSTANCE;
115115

116116
/**
117117
* A Locale scalar that accepts a IETF BCP 47 language tag string and produces {@link
118118
* java.util.Locale} objects at runtime.
119119
*/
120-
public static GraphQLScalarType Locale = new LocaleScalar();
120+
public static GraphQLScalarType Locale = LocaleScalar.INSTANCE;
121121

122122
/**
123123
* An `Int` scalar that MUST be greater than zero
124124
*
125125
* @see graphql.Scalars#GraphQLInt
126126
*/
127-
public static GraphQLScalarType PositiveInt = new PositiveIntScalar();
127+
public static GraphQLScalarType PositiveInt = PositiveIntScalar.INSTANCE;
128128
/**
129129
* An `Int` scalar that MUST be less than zero
130130
*
131131
* @see graphql.Scalars#GraphQLInt
132132
*/
133-
public static GraphQLScalarType NegativeInt = new NegativeIntScalar();
133+
public static GraphQLScalarType NegativeInt = NegativeIntScalar.INSTANCE;
134134
/**
135135
* An `Int` scalar that MUST be less than or equal to zero
136136
*
137137
* @see graphql.Scalars#GraphQLInt
138138
*/
139-
public static GraphQLScalarType NonPositiveInt = new NonPositiveIntScalar();
139+
public static GraphQLScalarType NonPositiveInt = NonPositiveIntScalar.INSTANCE;
140140
/**
141141
* An `Int` scalar that MUST be greater than or equal to zero
142142
*
143143
* @see graphql.Scalars#GraphQLInt
144144
*/
145-
public static GraphQLScalarType NonNegativeInt = new NonNegativeIntScalar();
145+
public static GraphQLScalarType NonNegativeInt = NonNegativeIntScalar.INSTANCE;
146146

147147
/**
148148
* An `Float` scalar that MUST be greater than zero
149149
*
150150
* @see graphql.Scalars#GraphQLFloat
151151
*/
152-
public static GraphQLScalarType PositiveFloat = new PositiveFloatScalar();
152+
public static GraphQLScalarType PositiveFloat = PositiveFloatScalar.INSTANCE;
153153
/**
154154
* An `Float` scalar that MUST be less than zero
155155
*
156156
* @see graphql.Scalars#GraphQLFloat
157157
*/
158-
public static GraphQLScalarType NegativeFloat = new NegativeFloatScalar();
158+
public static GraphQLScalarType NegativeFloat = NegativeFloatScalar.INSTANCE;
159159
/**
160160
* An `Float` scalar that MUST be less than or equal to zero
161161
*
162162
* @see graphql.Scalars#GraphQLFloat
163163
*/
164-
public static GraphQLScalarType NonPositiveFloat = new NonPositiveFloatScalar();
164+
public static GraphQLScalarType NonPositiveFloat = NonPositiveFloatScalar.INSTANCE;
165165
/**
166166
* An `Float` scalar that MUST be greater than or equal to zero
167167
*
168168
* @see graphql.Scalars#GraphQLFloat
169169
*/
170-
public static GraphQLScalarType NonNegativeFloat = new NonNegativeFloatScalar();
170+
public static GraphQLScalarType NonNegativeFloat = NonNegativeFloatScalar.INSTANCE;
171171

172172

173173
/**
@@ -177,6 +177,8 @@ public class ExtendedScalars {
177177
* The scalar converts any passed in objects to Strings first and them matches it against the provided
178178
* scalars to ensure its an acceptable value.
179179
*
180+
* @param name the name of the scalar
181+
*
180182
* @return a builder of a regex scalar
181183
*/
182184
public static RegexScalar.Builder newRegexScalar(String name) {
@@ -188,7 +190,6 @@ public static RegexScalar.Builder newRegexScalar(String name) {
188190
* <p>
189191
* For example you may take a `String` scalar and alias it as `SocialMediaLink` if that helps introduce
190192
* more semantic meaning to your type system.
191-
* <p>
192193
* <pre>
193194
* {@code
194195
*
@@ -201,6 +202,8 @@ public static RegexScalar.Builder newRegexScalar(String name) {
201202
* <p>
202203
* A future version of the graphql specification may add this capability but in the meantime you can use this facility.
203204
*
205+
* @param name the name of the aliased scalar
206+
*
204207
* @return a builder of a aliased scalar
205208
*/
206209
public static AliasedScalar.Builder newAliasedScalar(String name) {

src/main/java/graphql/scalars/alias/AliasedScalar.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import graphql.Assert;
44
import graphql.Internal;
5+
import graphql.language.Value;
56
import graphql.schema.Coercing;
67
import graphql.schema.CoercingParseLiteralException;
78
import graphql.schema.CoercingParseValueException;
@@ -14,7 +15,7 @@
1415
* Access this via {@link graphql.scalars.ExtendedScalars#newAliasedScalar(String)}
1516
*/
1617
@Internal
17-
public class AliasedScalar extends GraphQLScalarType {
18+
public class AliasedScalar {
1819

1920
/**
2021
* A builder for {@link graphql.scalars.alias.AliasedScalar}
@@ -63,20 +64,16 @@ public Builder aliasedScalar(GraphQLScalarType aliasedScalar) {
6364
/**
6465
* @return the built {@link AliasedScalar}
6566
*/
66-
public AliasedScalar build() {
67+
public GraphQLScalarType build() {
6768
Assert.assertNotNull(name);
6869
return aliasedScalarImpl(name, description, aliasedScalar);
6970
}
7071
}
7172

7273

73-
private AliasedScalar(String name, String description, Coercing coercing) {
74-
super(name, description, coercing);
75-
}
76-
77-
private static AliasedScalar aliasedScalarImpl(String name, String description, GraphQLScalarType aliasedScalar) {
74+
private static GraphQLScalarType aliasedScalarImpl(String name, String description, GraphQLScalarType aliasedScalar) {
7875
Assert.assertNotNull(aliasedScalar);
79-
return new AliasedScalar(name, description, new Coercing<Object, Object>() {
76+
Coercing<Object, Object> coercing = new Coercing<Object, Object>() {
8077
@Override
8178
public Object serialize(Object input) throws CoercingSerializeException {
8279
return aliasedScalar.getCoercing().serialize(input);
@@ -94,8 +91,19 @@ public Object parseLiteral(Object input) throws CoercingParseLiteralException {
9491

9592
@Override
9693
public Object parseLiteral(Object input, Map<String, Object> variables) throws CoercingParseLiteralException {
97-
return aliasedScalar.getCoercing().parseLiteral(input, variables);
94+
Coercing<?, ?> c = aliasedScalar.getCoercing();
95+
return c.parseLiteral(input, variables);
96+
}
97+
98+
@Override
99+
public Value<?> valueToLiteral(Object input) {
100+
return aliasedScalar.getCoercing().valueToLiteral(input);
98101
}
99-
});
102+
};
103+
return GraphQLScalarType.newScalar()
104+
.name(name)
105+
.description(description)
106+
.coercing(coercing)
107+
.build();
100108
}
101109
}

src/main/java/graphql/scalars/datetime/DateScalar.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import graphql.Internal;
44
import graphql.language.StringValue;
5+
import graphql.language.Value;
56
import graphql.schema.Coercing;
67
import graphql.schema.CoercingParseLiteralException;
78
import graphql.schema.CoercingParseValueException;
@@ -21,12 +22,14 @@
2122
* Access this via {@link graphql.scalars.ExtendedScalars#Date}
2223
*/
2324
@Internal
24-
public class DateScalar extends GraphQLScalarType {
25+
public class DateScalar {
2526

2627
private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
2728

28-
public DateScalar() {
29-
super("Date", "An RFC-3339 compliant Full Date Scalar", new Coercing<LocalDate, String>() {
29+
public static GraphQLScalarType INSTANCE;
30+
31+
static {
32+
Coercing<LocalDate, String> coercing = new Coercing<LocalDate, String>() {
3033
@Override
3134
public String serialize(Object input) throws CoercingSerializeException {
3235
TemporalAccessor temporalAccessor;
@@ -79,6 +82,12 @@ public LocalDate parseLiteral(Object input) throws CoercingParseLiteralException
7982
return parseLocalDate(((StringValue) input).getValue(), CoercingParseLiteralException::new);
8083
}
8184

85+
@Override
86+
public Value<?> valueToLiteral(Object input) {
87+
String s = serialize(input);
88+
return StringValue.newStringValue(s).build();
89+
}
90+
8291
private LocalDate parseLocalDate(String s, Function<String, RuntimeException> exceptionMaker) {
8392
try {
8493
TemporalAccessor temporalAccessor = dateFormatter.parse(s);
@@ -87,7 +96,12 @@ private LocalDate parseLocalDate(String s, Function<String, RuntimeException> ex
8796
throw exceptionMaker.apply("Invalid RFC3339 full date value : '" + s + "'. because of : '" + e.getMessage() + "'");
8897
}
8998
}
90-
});
91-
}
99+
};
92100

101+
INSTANCE = GraphQLScalarType.newScalar()
102+
.name("Date")
103+
.description("An RFC-3339 compliant Full Date Scalar")
104+
.coercing(coercing)
105+
.build();
106+
}
93107
}

src/main/java/graphql/scalars/datetime/DateTimeScalar.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import graphql.Internal;
44
import graphql.language.StringValue;
5+
import graphql.language.Value;
56
import graphql.schema.Coercing;
67
import graphql.schema.CoercingParseLiteralException;
78
import graphql.schema.CoercingParseValueException;
@@ -21,10 +22,12 @@
2122
* Access this via {@link graphql.scalars.ExtendedScalars#DateTime}
2223
*/
2324
@Internal
24-
public class DateTimeScalar extends GraphQLScalarType {
25+
public class DateTimeScalar {
2526

26-
public DateTimeScalar() {
27-
super("DateTime", "An RFC-3339 compliant DateTime Scalar", new Coercing<OffsetDateTime, String>() {
27+
public static GraphQLScalarType INSTANCE;
28+
29+
static {
30+
Coercing<OffsetDateTime, String> coercing = new Coercing<OffsetDateTime, String>() {
2831
@Override
2932
public String serialize(Object input) throws CoercingSerializeException {
3033
OffsetDateTime offsetDateTime;
@@ -75,14 +78,26 @@ public OffsetDateTime parseLiteral(Object input) throws CoercingParseLiteralExce
7578
return parseOffsetDateTime(((StringValue) input).getValue(), CoercingParseLiteralException::new);
7679
}
7780

81+
@Override
82+
public Value<?> valueToLiteral(Object input) {
83+
String s = serialize(input);
84+
return StringValue.newStringValue(s).build();
85+
}
86+
7887
private OffsetDateTime parseOffsetDateTime(String s, Function<String, RuntimeException> exceptionMaker) {
7988
try {
8089
return OffsetDateTime.parse(s, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
8190
} catch (DateTimeParseException e) {
8291
throw exceptionMaker.apply("Invalid RFC3339 value : '" + s + "'. because of : '" + e.getMessage() + "'");
8392
}
8493
}
85-
});
94+
};
95+
96+
INSTANCE = GraphQLScalarType.newScalar()
97+
.name("DateTime")
98+
.description("An RFC-3339 compliant DateTime Scalar")
99+
.coercing(coercing)
100+
.build();
86101
}
87102

88103
}

src/main/java/graphql/scalars/datetime/TimeScalar.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import graphql.Internal;
44
import graphql.language.StringValue;
5+
import graphql.language.Value;
56
import graphql.schema.Coercing;
67
import graphql.schema.CoercingParseLiteralException;
78
import graphql.schema.CoercingParseValueException;
@@ -21,12 +22,14 @@
2122
* Access this via {@link graphql.scalars.ExtendedScalars#Time}
2223
*/
2324
@Internal
24-
public class TimeScalar extends GraphQLScalarType {
25+
public class TimeScalar {
2526

2627
private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_OFFSET_TIME;
2728

28-
public TimeScalar() {
29-
super("Time", "An RFC-3339 compliant Full Time Scalar", new Coercing<OffsetTime, String>() {
29+
public static GraphQLScalarType INSTANCE;
30+
31+
static {
32+
Coercing<OffsetTime, String> coercing = new Coercing<OffsetTime, String>() {
3033
@Override
3134
public String serialize(Object input) throws CoercingSerializeException {
3235
TemporalAccessor temporalAccessor;
@@ -79,6 +82,12 @@ public OffsetTime parseLiteral(Object input) throws CoercingParseLiteralExceptio
7982
return parseOffsetTime(((StringValue) input).getValue(), CoercingParseLiteralException::new);
8083
}
8184

85+
@Override
86+
public Value<?> valueToLiteral(Object input) {
87+
String s = serialize(input);
88+
return StringValue.newStringValue(s).build();
89+
}
90+
8291
private OffsetTime parseOffsetTime(String s, Function<String, RuntimeException> exceptionMaker) {
8392
try {
8493
TemporalAccessor temporalAccessor = dateFormatter.parse(s);
@@ -87,7 +96,13 @@ private OffsetTime parseOffsetTime(String s, Function<String, RuntimeException>
8796
throw exceptionMaker.apply("Invalid RFC3339 full time value : '" + s + "'. because of : '" + e.getMessage() + "'");
8897
}
8998
}
90-
});
99+
};
100+
101+
INSTANCE = GraphQLScalarType.newScalar()
102+
.name("Time")
103+
.description("An RFC-3339 compliant Full Time Scalar")
104+
.coercing(coercing)
105+
.build();
91106
}
92107

93108
}

0 commit comments

Comments
 (0)