Skip to content

Commit 4b35f38

Browse files
dondonzhwillson
andauthored
Add contributed custom scalars announcement blog (#1320)
* Add contributed custom scalars announcement blog * Adjust file date; slight grammar tweak Co-authored-by: hwillson <hugh@octonary.com>
1 parent 5a0b7f4 commit 4b35f38

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: GraphQL Custom Scalar specifications
3+
tags: ["announcements"]
4+
layout: blog
5+
date: 2022-12-01
6+
byline: Andreas Marek, Donna Zhou
7+
permalink: /blog/2022-12-01-custom-scalars
8+
---
9+
10+
# Announcing contributed GraphQL custom scalar specifications
11+
12+
We are very happy to announce the official home for contributed GraphQL [custom scalar](https://spec.graphql.org/draft/#sec-Scalars.Custom-Scalars) specifications at [scalars.graphql.org](https://scalars.graphql.org/).
13+
14+
You are welcome to [contribute](https://scalars.graphql.org/new-scalar) custom scalar specifications. Once your specification is merged in, it will be hosted at `scalars.graphql.org/<GitHub-username>/<specification-name>`.
15+
16+
Our first contributed specification is for [DateTime](https://scalars.graphql.org/andimarek/date-time). You can point users to the specification's URL with the built-in `@specifiedBy` [directive](https://spec.graphql.org/draft/#sec--specifiedBy) in your GraphQL schema.
17+
18+
```graphql
19+
scalar DateTime @specifiedBy(url: "https://scalars.graphql.org/andimarek/date-time")
20+
```
21+
22+
## Why we need custom scalar specifications
23+
We were inspired to start this project after an incident at work caused by a difference in `DateTime` implementations in two GraphQL services. The problem was a difference in how many digits were used to represent a fraction of a second. This incident highlighted a flaw in the often cited [RFC-3339 specification](https://www.ietf.org/rfc/rfc3339.txt), which does not explicitly state the number of digits to be used to represent a fraction of a second.
24+
25+
To prevent such incidents in the future, we created a [refined version](https://scalars.graphql.org/andimarek/date-time) of the RFC-3339 specification, so that `DateTime` scalars can be consistently implemented in any GraphQL service. We thought others might be interested in our `DateTime` specification too, so we created a [repository](https://github.com/graphql/graphql-scalars) to share custom scalar specifications.
26+
27+
We wanted to make documentation easy and use the built-in `@specifiedBy` directive to reference specifications. We have set up a public and official GraphQL Foundation-owned domain to host specifications. Your contributed specifications will be published at `scalars.graphql.org/<GitHub-username>/<specification-name>`.
28+
29+
You can reference specifications inside a schema as follows:
30+
31+
```graphql
32+
scalar DateTime @specifiedBy(url: "https://scalars.graphql.org/andimarek/date-time")
33+
```
34+
35+
You can also reference specifications inside custom scalar implementations, for example in the `graphql-java-extended-scalars` [DateTime scalar](https://github.com/graphql-java/graphql-java-extended-scalars/blob/master/src/main/java/graphql/scalars/datetime/DateTimeScalar.java#L113).
36+
37+
## How to contribute custom scalar specifications
38+
See the [contribution guide](https://scalars.graphql.org/new-scalar) and the [implementation guide](https://scalars.graphql.org/guide). We have included a [general template](https://scalars.graphql.org/template) and a more [simplified template for String-based scalars](https://scalars.graphql.org/template-string).
39+
40+
Open a pull request on the [graphql-scalars GitHub repository](https://github.com/graphql/graphql-scalars) to add your custom scalar specification. Once merged, your specification will be hosted at `scalars.graphql.org/<GitHub-username>/<specification-name>`.
41+
42+
## Get involved!
43+
If you have any comments or questions, please open an issue on the [graphql-scalars GitHub repository](https://github.com/graphql/graphql-scalars).
44+
45+
We hope to avoid incidents in the future by making it easier to document, standardize, and share custom scalar specifications. We are looking forward to seeing your custom scalar specifications!

0 commit comments

Comments
 (0)