JSON, URL, Email, Timestamp, and IPAddress scalars added

JSON, URL, Email, Timestamp, and IPAddress scalars added

We're extremely happy to announce the release of 5 new scalars:

These can be used inside of your schema to attribute certain fields to the type they are, as well as benefiting from the validations those bring. If any data doesn't meet the requirements of each scalar, an error with be thrown.

Let's take a look at how these can be used in our schema, mutating data, as well as the different specifications these scalars relate to.

With the ECMA-404 specification you can now set which field is a JSON object:

type Order @model {
  id: ID!
  metadata: JSON
}

Simply pass valid JSON when mutating data:

mutation {
  orderCreate(input: { metadata: { stripeCheckoutId: "abc" } }) {
    order {
      metadata
    }
  }
}

The URL scalar conforms to the URL standard which can be used to set fields as a URL:

type User @model {
  id: ID!
  avatarUrl: URL
}

Simply pass a valid URL when mutating data:

mutation {
  userCreate(input: { avatarUrl: "https://github.com/notrab.png" }) {
    user {
      avatarUrl
    }
  }
}

The new Email scalar conforms to the HTML Spec which can be used to set fields as a Email:

type User @model {
  id: ID!
  email: Email
}

Simply pass a valid email when mutating data:

mutation {
  userCreate(input: { email: "[email protected]" }) {
    user {
      email
    }
  }
}

The new Timestamp scalar conforms to the Unix epoch format.

You can use this inside your schema by providing Timestamp for the desired field:

type Activity @model {
  id: ID!
  when: Timestamp
}

Simply pass a valid timestamp when mutating data:

mutation {
  activityCreate(input: { when: 1662032540 }) {
    activity {
      when
    }
  }
}

A valid IPv4 or IPv6 address. IPv4 addresses are expected in quad-dotted notation 123.123.123.123. IPv6 addresses are expected in non-bracketed, colon-separated format 1a2b:3c4b::1234:4567.

To opt-into this behaviour, use the IPAddress scalar for the desired field:

type Activity @model {
  id: ID!
  ip: IPAddress
}

Simply pass a valid IP Address when mutating data:

mutation NewIPV4Activity {
  activityCreate(input: { ip: "123.123.123.123" }) {
    activity {
      ip
    }
  }
}

mutation NewIPV6Activity {
  activityCreate(input: { ip: "1a2b:3c4b::1234:4567" }) {
    activity {
      ip
    }
  }
}
  • Grafbase CLI 0.6.0 has been released to include all of the above. If upgrading from versions before 0.4.0 you'll want to delete the .grafbase folder.
  • Grafbase CLI 0.6.0 also fixes cursor support in paginated queries, and the order of results using last.

We'd love to hear your feedback and ideas, so join us on Discord.