graphql / graphql/graphql-spec

Specifying the literal value type of a custom scalar

Open
#1,139 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I was surprised to find there is no way to declare a custom scalar type with it's actual value type?

When declaring something like:

```graphql
scalar Date
```

It's all down to run-time type-checking for actual `Date` literal values.

I was expecting something like:

```graphql
scalar Date : String
```

vs

```graphql
scalar Date : Int
```

I understand we can't statically verify the actual contents of e.g. a `Date` beyond the fact that it's a `String` or `Int`, but a literal could at least be validated (statically) for the correct literal value type, which would be better than nothing, wouldn't it?

At run-time, of course, there would be further validatio - but statically, a scalar is almost like a type alias, and could at least be validated as such, I think?

(Sorry if this has already been asked - it seems like this would be a common question for someone learning GraphQL, but I've read through dozens of issues and I couldn't find this question asked or answered.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.