# GraphQL custom scalar types

**URL:** <https://discuss.dgraph.io/t/graphql-custom-scalar-types/16742>\
**Category:** GraphQL\
**Tags:** kind:feature\
**Created:** [February 1, 2022, 12:01am UTC](https://discuss.dgraph.io/t/graphql-custom-scalar-types/16742 "2022-02-01T00:01:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johannes](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@johannes](https://discuss.dgraph.io/u/johannes)\
**Post date:** [February 1, 2022, 12:01am UTC](https://discuss.dgraph.io/t/graphql-custom-scalar-types/16742/1 "2022-02-01T00:01:29Z")

</div>

Hello,

Dgraph has several **custom scalar types** implemented for GraphQL such as DateTime, Polygon and Int64.

But there’s no ability yet to specify additional custom scalar types (and resolvers/ serialization/ validation).

The most common custom scalar types I have used so far were:

- Email,
- URI, DOI, ISRC (music records), UPC (trade items)
- PhoneNumber
- Time, Date, DateRange
- TimeCode
- Bézier
- Symbol (e.g. for a single Emoji)
- Coordinates {x: …,y: …, z: …}
- Colors: RGB(A), HEX, HSL(A),
- Array (with preserved order and duplicates),
- JSON

Of course one can always encode as a string. But what I love about Dgraph ist that it can drastically simplify my business logic and I can use it as an all-in-one backend service.

An alternative to custom scalar types would be the addition of [@constraint directives](https://www.npmjs.com/package/graphql-constraint-directive) for validation:

```auto
email: String! @constraint(format: "email", maxLength: 255)

```

As far as I understand custom remote fields or lambda fields are the recommended (?) workaround in Dgraph (without search however).

---

<div class="post-metadata">

**Author:** ![jdgamble555](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jdgamble555/32/7503_2.png) [@jdgamble555](https://discuss.dgraph.io/u/jdgamble555)\
**Post date:** [February 1, 2022, 12:13am UTC](https://discuss.dgraph.io/t/graphql-custom-scalar-types/16742/2 "2022-02-01T00:13:40Z")

</div>

Great idea! But yes, that is the only workaround the way DGraph currently stands.

J

---

<div class="post-metadata">

**Author:** ![Leave\_Trails](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/leave_trails/32/9777_2.png) [@Leave\_Trails](https://discuss.dgraph.io/u/Leave_Trails)\
**Post date:** [October 12, 2022, 11:06am UTC](https://discuss.dgraph.io/t/graphql-custom-scalar-types/16742/3 "2022-10-12T11:06:21Z")

</div>

+1 for this functionality.  
It should be easy to implement just to rename string to other scalar type but then when it is exposed by schema I could teach my client library to parse this scalar type to something more meaningful.

---

<div class="post-metadata">

**Author:** ![Yaroslav\_Kuznetsov](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/yaroslav_kuznetsov/32/10612_2.png) [@Yaroslav\_Kuznetsov](https://discuss.dgraph.io/u/Yaroslav_Kuznetsov)\
**Post date:** [September 12, 2023, 6:29am UTC](https://discuss.dgraph.io/t/graphql-custom-scalar-types/16742/4 "2023-09-12T06:29:27Z")

</div>

Any updates? 🙂
