Skip to content

Commit fa2fd41

Browse files
committed
Updating to graphql-java 17.x and fixing the class constructors
1 parent f4f9cb9 commit fa2fd41

22 files changed

+705
-569
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repositories {
3939

4040

4141
dependencies {
42-
compile "com.graphql-java:graphql-java:16.1"
42+
compile "com.graphql-java:graphql-java:0.0.0-2021-06-27T12-22-33-cd2bab76"
4343

4444
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
4545
testCompile 'org.codehaus.groovy:groovy-all:2.4.13'

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

Lines changed: 15 additions & 15 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
/**

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

Lines changed: 16 additions & 9 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);
@@ -96,6 +93,16 @@ public Object parseLiteral(Object input) throws CoercingParseLiteralException {
9693
public Object parseLiteral(Object input, Map<String, Object> variables) throws CoercingParseLiteralException {
9794
return aliasedScalar.getCoercing().parseLiteral(input, variables);
9895
}
99-
});
96+
97+
@Override
98+
public Value valueToLiteral(Object input) {
99+
return aliasedScalar.getCoercing().valueToLiteral(input);
100+
}
101+
};
102+
return GraphQLScalarType.newScalar()
103+
.name(name)
104+
.description(description)
105+
.coercing(coercing)
106+
.build();
100107
}
101108
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
* Access this via {@link graphql.scalars.ExtendedScalars#Date}
2222
*/
2323
@Internal
24-
public class DateScalar extends GraphQLScalarType {
24+
public class DateScalar {
2525

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

28-
public DateScalar() {
29-
super("Date", "An RFC-3339 compliant Full Date Scalar", new Coercing<LocalDate, String>() {
28+
public static GraphQLScalarType INSTANCE;
29+
30+
static {
31+
Coercing<LocalDate, String> coercing = new Coercing<LocalDate, String>() {
3032
@Override
3133
public String serialize(Object input) throws CoercingSerializeException {
3234
TemporalAccessor temporalAccessor;
@@ -87,7 +89,12 @@ private LocalDate parseLocalDate(String s, Function<String, RuntimeException> ex
8789
throw exceptionMaker.apply("Invalid RFC3339 full date value : '" + s + "'. because of : '" + e.getMessage() + "'");
8890
}
8991
}
90-
});
91-
}
92+
};
9293

94+
INSTANCE = GraphQLScalarType.newScalar()
95+
.name("Date")
96+
.description("An RFC-3339 compliant Full Date Scalar")
97+
.coercing(coercing)
98+
.build();
99+
}
93100
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
* Access this via {@link graphql.scalars.ExtendedScalars#DateTime}
2222
*/
2323
@Internal
24-
public class DateTimeScalar extends GraphQLScalarType {
24+
public class DateTimeScalar {
2525

26-
public DateTimeScalar() {
27-
super("DateTime", "An RFC-3339 compliant DateTime Scalar", new Coercing<OffsetDateTime, String>() {
26+
public static GraphQLScalarType INSTANCE;
27+
28+
static {
29+
Coercing<OffsetDateTime, String> coercing = new Coercing<OffsetDateTime, String>() {
2830
@Override
2931
public String serialize(Object input) throws CoercingSerializeException {
3032
OffsetDateTime offsetDateTime;
@@ -82,7 +84,13 @@ private OffsetDateTime parseOffsetDateTime(String s, Function<String, RuntimeExc
8284
throw exceptionMaker.apply("Invalid RFC3339 value : '" + s + "'. because of : '" + e.getMessage() + "'");
8385
}
8486
}
85-
});
87+
};
88+
89+
INSTANCE = GraphQLScalarType.newScalar()
90+
.name("DateTime")
91+
.description("An RFC-3339 compliant DateTime Scalar")
92+
.coercing(coercing)
93+
.build();
8694
}
8795

8896
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
* Access this via {@link graphql.scalars.ExtendedScalars#Time}
2222
*/
2323
@Internal
24-
public class TimeScalar extends GraphQLScalarType {
24+
public class TimeScalar {
2525

2626
private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_OFFSET_TIME;
2727

28-
public TimeScalar() {
29-
super("Time", "An RFC-3339 compliant Full Time Scalar", new Coercing<OffsetTime, String>() {
28+
public static GraphQLScalarType INSTANCE;
29+
30+
static {
31+
Coercing<OffsetTime, String> coercing = new Coercing<OffsetTime, String>() {
3032
@Override
3133
public String serialize(Object input) throws CoercingSerializeException {
3234
TemporalAccessor temporalAccessor;
@@ -87,7 +89,13 @@ private OffsetTime parseOffsetTime(String s, Function<String, RuntimeException>
8789
throw exceptionMaker.apply("Invalid RFC3339 full time value : '" + s + "'. because of : '" + e.getMessage() + "'");
8890
}
8991
}
90-
});
92+
};
93+
94+
INSTANCE = GraphQLScalarType.newScalar()
95+
.name("Time")
96+
.description("An RFC-3339 compliant Full Time Scalar")
97+
.coercing(coercing)
98+
.build();
9199
}
92100

93101
}

0 commit comments

Comments
 (0)