Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6a38e82

Browse files
authoredMar 12, 2023
Merge pull request #93 from setchy/docs/readme-graphql-scalars-spec
docs: update to reference scalars.graphql.org specification for DateTime
2 parents 5eea2c3 + d5ff29c commit 6a38e82

File tree

1 file changed

+180
-198
lines changed

1 file changed

+180
-198
lines changed
 

‎README.md

Lines changed: 180 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
[![Latest Snapshot](https://img.shields.io/maven-central/v/com.graphql-java/graphql-java-extended-scalars?label=maven-central%20snapshot)](https://maven-badges.herokuapp.com/maven-central/com.graphql-java/graphql-java-extended-scalars/)
66
[![MIT licensed](https://img.shields.io/badge/license-MIT-green)](https://github.com/graphql-java/graphql-java-extended-scalars/blob/master/LICENSE.md)
77

8-
98
This library provides extended scalars for [graphql-java](https://github.com/graphql-java/graphql-java)
109

1110
Scalars in graphql are the leaf nodes of a query, the non-compound values that can't be queried further via sub-field selections.
1211

13-
The graphql standard specifies that the `String`, `Int`, `Float`, `Boolean` and `ID` scalars must be present in a graphql type
12+
The graphql standard specifies that the `String`, `Int`, `Float`, `Boolean` and `ID` scalars must be present in a graphql type
1413
system but after that it is up to an implementation about what custom scalars are present.
1514

1615
You would use custom scalars when you want to describe more meaningful behavior or ranges of values.
1716

1817
## How to install
18+
1919
To use this library put the following into your gradle config
2020

2121
implementation 'com.graphql-java:graphql-java-extended-scalars:20.0'
22-
22+
2323
or the following into your Maven config
2424

2525
<dependency>
@@ -31,17 +31,17 @@ or the following into your Maven config
3131
> Note:
3232
>
3333
> use 19.0 or above for graphql-java 19.x and above
34-
>
34+
>
3535
> use 20.0 or above for graphql-java 20.x and above
3636
37-
3837
It's currently available from Maven Central.
3938

4039
## How to use extended scalars
40+
4141
Register the scalar with graphql-java
4242

4343
RuntimeWiring.newRuntimeWiring().scalar(ExtendedScalars.DateTime)
44-
44+
4545
Or if using [Spring for GraphQL](https://docs.spring.io/spring-graphql/docs/current/reference/html/), register the scalar with `RuntimeWiringConfigurer`
4646

4747
@Configuration
@@ -53,172 +53,157 @@ Or if using [Spring for GraphQL](https://docs.spring.io/spring-graphql/docs/curr
5353
}
5454

5555
And use the scalar in your schema
56-
56+
5757
scalar DateTime
5858
type Something {
5959
someDateTime: DateTime
6060
}
6161

6262
## DateTime Scalars
6363

64-
* `DateTime`
65-
* An RFC-3339 compliant date time scalar that accepts string values like `1996-12-19T16:39:57-08:00` and produces
66-
`java.time.OffsetDateTime` objects at runtime
67-
* `Time`
68-
* An RFC-3339 compliant time scalar that accepts string values like `16:39:57-08:00` and produces
69-
`java.time.OffsetTime` objects at runtime
70-
* `LocalTime`
71-
* 24-hour clock time string in the format `hh:mm:ss.sss` or `hh:mm:ss` if partial seconds is zero and
72-
produces `java.time.LocalTime` objects at runtime.
73-
* `Date`
74-
* An RFC-3339 compliant date scalar that accepts string values like `1996-12-19` and produces
75-
`java.time.LocalDate` objects at runtime
76-
77-
See [the rfc3339 spec](https://www.ietf.org/rfc/rfc3339.txt) for more details on the format.
64+
- `DateTime` - [specification](https://scalars.graphql.org/andimarek/date-time.html)
65+
- See specification
66+
- An RFC-3339 compliant date time scalar that accepts string values like `1996-12-19T16:39:57-08:00` and produces
67+
`java.time.OffsetDateTime` objects at runtime.
68+
- `Time`
69+
- An RFC-3339 compliant time scalar that accepts string values like `16:39:57-08:00` and produces
70+
`java.time.OffsetTime` objects at runtime
71+
- `LocalTime`
72+
- 24-hour clock time string in the format `hh:mm:ss.sss` or `hh:mm:ss` if partial seconds is zero and
73+
produces `java.time.LocalTime` objects at runtime.
74+
- `Date`
75+
- An RFC-3339 compliant date scalar that accepts string values like `1996-12-19` and produces
76+
`java.time.LocalDate` objects at runtime
7877

7978
An example declaration in SDL might be:
8079

8180
```graphql
82-
83-
type Customer {
84-
birthDay : Date
85-
workStartTime : Time
86-
bornAt : DateTime
87-
}
88-
89-
type Query {
90-
customers(bornAfter : DateTime) : [Customers]
91-
}
92-
93-
```
81+
type Customer {
82+
birthDay: Date
83+
workStartTime: Time
84+
bornAt: DateTime
85+
}
86+
87+
type Query {
88+
customers(bornAfter: DateTime): [Customers]
89+
}
90+
```
9491

9592
And example query might look like:
93+
9694
```graphql
97-
98-
query {
99-
customers(bornAfter : "1996-12-19T16:39:57-08:00") {
100-
birthDay
101-
bornAt
102-
}
103-
}
104-
105-
```
95+
query {
96+
customers(bornAfter: "1996-12-19T16:39:57-08:00") {
97+
birthDay
98+
bornAt
99+
}
100+
}
101+
```
102+
106103
## ID Scalars
107104

108-
* `UUID`
109-
* A universally unique identifier scalar that accepts uuid values like `2423f0a0-3b81-4115-a189-18df8b35e8fc` and produces
105+
- `UUID`
106+
- A universally unique identifier scalar that accepts uuid values like `2423f0a0-3b81-4115-a189-18df8b35e8fc` and produces
110107
`java.util.UUID` instances at runtime.
111108

112109
## Object / JSON Scalars
113110

114-
* `Object`
115-
* An object scalar that accepts any object as a scalar value
111+
- `Object`
112+
113+
- An object scalar that accepts any object as a scalar value
114+
115+
- `JSON`
116+
- A synonym for the `Object` scalar, it will accept any object as a scalar value
116117

117-
* `JSON`
118-
* A synonym for the `Object` scalar, it will accept any object as a scalar value
119-
120118
One of the design goals of graphql, is that the type system describes the shape of the data returned.
121119

122-
The `Object` / `JSON` scalars work against this some what because they can return compound values outside the type system. As such
123-
they should be used sparingly. In general your should aim to describe the data via the graphql type system where you can and only
124-
resort to the `Object` / `JSON` scalars in very rare circumstances.
120+
The `Object` / `JSON` scalars work against this some what because they can return compound values outside the type system. As such
121+
they should be used sparingly. In general your should aim to describe the data via the graphql type system where you can and only
122+
resort to the `Object` / `JSON` scalars in very rare circumstances.
125123

126-
An example might be an extensible graphql system where systems can input custom metadata objects that cant be known at
124+
An example might be an extensible graphql system where systems can input custom metadata objects that cant be known at
127125
schema type design time.
128126

129127
An example declaration in SDL might be:
130128

131129
```graphql
132-
133-
type Customer {
134-
name : String
135-
associatedMetaData : JSON
136-
}
137-
138-
type Query {
139-
customers(filterSyntax : JSON) : [Customers]
140-
}
141-
142-
```
130+
type Customer {
131+
name: String
132+
associatedMetaData: JSON
133+
}
134+
135+
type Query {
136+
customers(filterSyntax: JSON): [Customers]
137+
}
138+
```
143139

144140
And example query might look like:
145141

146142
```graphql
147-
148-
query {
149-
customers(filterSyntax : {
150-
startSpan : "First",
151-
matchCriteria : {
152-
countryCode : "AU",
153-
isoCodes : ["27B-34R", "95A-E23"],
154-
155-
}
156-
}) {
157-
name
158-
associatedMetaData
159-
}
143+
query {
144+
customers(
145+
filterSyntax: {
146+
startSpan: "First"
147+
matchCriteria: { countryCode: "AU", isoCodes: ["27B-34R", "95A-E23"] }
160148
}
161-
162-
```
163-
164-
Note : The `JSON` scalar is a simple alias type to the `Object` scalar because often the returned data is a blob of JSON. They are
165-
all just objects at runtime in graphql-java terms and what network serialisation protocol is up to you. Choose whichever name you think
166-
adds more semantic readers to your schema consumers.
149+
) {
150+
name
151+
associatedMetaData
152+
}
153+
}
154+
```
167155

156+
Note : The `JSON` scalar is a simple alias type to the `Object` scalar because often the returned data is a blob of JSON. They are
157+
all just objects at runtime in graphql-java terms and what network serialisation protocol is up to you. Choose whichever name you think
158+
adds more semantic readers to your schema consumers.
168159

169160
## Numeric Scalars
170161

171-
172-
* `PositiveInt`
173-
* An `Int` scalar that MUST be greater than zero
174-
* `NegativeInt`
175-
* An `Int` scalar that MUST be less than zero
176-
* `NonPositiveInt`
177-
* An `Int` scalar that MUST be less than or equal to zero
178-
* `NonNegativeInt`
179-
* An `Int` scalar that MUST be greater than or equal to zero
180-
* `PositiveFloat`
181-
* An `Float` scalar that MUST be greater than zero
182-
* `NegativeFloat`
183-
* An `Float` scalar that MUST be less than zero
184-
* `NonPositiveFloat`
185-
* An `Float` scalar that MUST be less than or equal to zero
186-
* `NonNegativeFloat`
187-
* An `Float` scalar that MUST be greater than or equal to zero
162+
- `PositiveInt`
163+
- An `Int` scalar that MUST be greater than zero
164+
- `NegativeInt`
165+
- An `Int` scalar that MUST be less than zero
166+
- `NonPositiveInt`
167+
- An `Int` scalar that MUST be less than or equal to zero
168+
- `NonNegativeInt`
169+
- An `Int` scalar that MUST be greater than or equal to zero
170+
- `PositiveFloat`
171+
- An `Float` scalar that MUST be greater than zero
172+
- `NegativeFloat`
173+
- An `Float` scalar that MUST be less than zero
174+
- `NonPositiveFloat`
175+
- An `Float` scalar that MUST be less than or equal to zero
176+
- `NonNegativeFloat`
177+
- An `Float` scalar that MUST be greater than or equal to zero
188178

189179
The numeric scalars are derivations of the standard graphql `Int` and `Float` scalars that enforce range limits.
190180

191181
An example declaration in SDL might be:
192182

193183
```graphql
194-
195-
type Customer {
196-
name : String
197-
currentHeight : PositiveInt
198-
weightLossGoal : NonPositiveInt
199-
averageWeightLoss : NegativeFloat
200-
}
201-
202-
type Query {
203-
customers(height : PositiveInt) : [Customers]
204-
}
205-
206-
```
184+
type Customer {
185+
name: String
186+
currentHeight: PositiveInt
187+
weightLossGoal: NonPositiveInt
188+
averageWeightLoss: NegativeFloat
189+
}
190+
191+
type Query {
192+
customers(height: PositiveInt): [Customers]
193+
}
194+
```
207195

208196
And example query might look like:
209197

210198
```graphql
211-
212-
query {
213-
customers(height : 182) {
214-
name
215-
height
216-
weightLossGoal
217-
}
218-
}
219-
220-
```
221-
199+
query {
200+
customers(height: 182) {
201+
name
202+
height
203+
weightLossGoal
204+
}
205+
}
206+
```
222207

223208
## Regex Scalars
224209

@@ -239,89 +224,90 @@ For example, imagine a `phoneNumber` scalar like this :
239224

240225
## Locale Scalar
241226

242-
The Locale scalar handles [IETF BCP 47](https://tools.ietf.org/html/bcp47) language tags via the
243-
JDK method [Locale.forLanguageTag](https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#forLanguageTag(java.lang.String))
227+
The Locale scalar handles [IETF BCP 47](https://tools.ietf.org/html/bcp47) language tags via the
228+
JDK method [Locale.forLanguageTag](<https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#forLanguageTag(java.lang.String)>)
244229

245230
```graphql
246-
247-
type Customer {
248-
name : String
249-
locale : Locale
250-
}
251-
252-
type Query {
253-
customers(inLocale : Locale) : [Customers]
254-
}
255-
```
231+
type Customer {
232+
name: String
233+
locale: Locale
234+
}
235+
236+
type Query {
237+
customers(inLocale: Locale): [Customers]
238+
}
239+
```
256240

257241
An example query to look for customers in the Romanian locale might look like:
258242

259243
```graphql
260-
261-
query {
262-
customers(inLocale : "ro-RO") {
263-
name
264-
locale
265-
}
266-
}
267-
268-
```
244+
query {
245+
customers(inLocale: "ro-RO") {
246+
name
247+
locale
248+
}
249+
}
250+
```
251+
269252
## Country Code Scalar
270-
The CountryCode scalar type as defined by [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
271253

254+
The CountryCode scalar type as defined by [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
272255

273256
An example declaration in SDL might be:
257+
274258
```graphql
275-
scalar CountryCode
259+
scalar CountryCode
276260

277-
type Customer {
278-
name : String
279-
countryCode : CountryCode
280-
}
281-
```
261+
type Customer {
262+
name: String
263+
countryCode: CountryCode
264+
}
265+
```
282266

283267
And example query might look like:
284268

285269
```graphql
286-
query {
287-
customers(code : "US") {
288-
name
289-
countryCode
290-
}
291-
}
292-
```
270+
query {
271+
customers(code: "US") {
272+
name
273+
countryCode
274+
}
275+
}
276+
```
277+
293278
## Currency Scalar
294279

295280
A field whose value is an [ISO-4217](https://en.wikipedia.org/wiki/ISO_4217) currency.
296281

297282
An example declaration in SDL might be:
283+
298284
```graphql
299-
scalar Currency
285+
scalar Currency
300286

301-
type Account {
302-
id : String
303-
currency : Currency
304-
accountNumber: String
305-
}
306-
```
287+
type Account {
288+
id: String
289+
currency: Currency
290+
accountNumber: String
291+
}
292+
```
307293

308294
And example query might look like:
309295

310296
```graphql
311-
query {
312-
accounts(currency : "USD") {
313-
id
314-
currency
315-
accountNumber
316-
}
317-
}
318-
```
297+
query {
298+
accounts(currency: "USD") {
299+
id
300+
currency
301+
accountNumber
302+
}
303+
}
304+
```
319305

320306
## Alias Scalars
321307

322308
You can create aliases for existing scalars to add more semantic meaning to them.
323309

324-
For example a link to a social media post could be representing by a `String` but the name `SocialMediaLink` is a
310+
For example a link to a social media post could be representing by a `String` but the name `SocialMediaLink` is a
325311
more semantically meaningful name for that scalar type.
326312

327313
For example, you would build it like this:
@@ -337,35 +323,31 @@ For example, you would build it like this:
337323
And use it in a SDL schema like this :
338324

339325
```graphql
340-
341-
type Customer {
342-
name : String
343-
socialMediaLink : SocialMediaLink
344-
}
345-
326+
type Customer {
327+
name: String
328+
socialMediaLink: SocialMediaLink
329+
}
346330
```
347331

348332
Note: A future version of the graphql specification may add this capability but in the meantime you can use this facility.
349333

350334
## Java Primitives
351-
* `GraphQLLong`
352-
* A scalar which represents `java.lang.Long`
353-
* `GraphQLShort`
354-
* A scalar which represents `java.lang.Short`
355-
* `GraphQLByte`
356-
* A scalar which represents `java.lang.Byte`
357-
* `GraphQLBigDecimal`
358-
* A scalar which represents `java.math.BigDecimal`
359-
* `GraphQLBigInteger`
360-
* A scalar which represents `java.math.BigInteger`
361-
* `GraphQLChar`
362-
* A scalar which represents `java.lang.Character`
363335

336+
- `GraphQLLong`
337+
- A scalar which represents `java.lang.Long`
338+
- `GraphQLShort`
339+
- A scalar which represents `java.lang.Short`
340+
- `GraphQLByte`
341+
- A scalar which represents `java.lang.Byte`
342+
- `GraphQLBigDecimal`
343+
- A scalar which represents `java.math.BigDecimal`
344+
- `GraphQLBigInteger`
345+
- A scalar which represents `java.math.BigInteger`
346+
- `GraphQLChar`
347+
- A scalar which represents `java.lang.Character`
364348

365349
## Other Scalars
366350

367-
* `Url`
368-
* An url scalar that accepts string values like `https://www.w3.org/Addressing/URL/url-spec.txt` and produces
369-
`java.net.URL` objects at runtime
370-
371-
351+
- `Url`
352+
- An url scalar that accepts string values like `https://www.w3.org/Addressing/URL/url-spec.txt` and produces
353+
`java.net.URL` objects at runtime

0 commit comments

Comments
 (0)
Please sign in to comment.