Skip to content

title = "@bb-scalar"


Define your own custom scalar (fundamental) type.



scalar Identifier @bb_scalar(_type: ScalarType )


Type: String
Values: Int | Float | String | ID | Boolean | Date | DateTime | Base64 | Void


@bb_scalar allows you to define your own custom scalar types. You might want to do this to indicate logical meaning to your scalar types. For example, instead of an integer for number of days i.e. GraphQL scalar type Int, you create a new type called NoOfDays defined like this:

scalar NoOfDays @bb_scalar(_type: "Int")

This new scalar type can then be used in any field that indicates number of days or as a return value for an operation that returns the number of days of any period (for example).

The values of the @bb_scalar directive _type argument correspond to either the built-in GraphQL scalar types or to specific scalar types that basebox has built (we will continually be extending this type). These types also correspond to Postgres data types as well. The following table indicates all the scalar types available for usage in the @bb_scalar directive's _type argument as well as the corresponding PostgreSQL types:

GraphQL PostgreSQL
Float FLOAT8
Base64 BYTEA
Void no equivalent

Void is a special type that does not have a PostgreSQL equivalent. It is used to indicate that an operation does not return any values and cannot be used to define a field but only as an operation return value.


DateTime Example
scalar Date @bb_scalar(_type: "Date")

type Patient {
  id: ID!
  name: String
  dateOfBirth: Date
In the above example, we declare a Date scalar type and use it to create a date of birth field of type Date.

Base64 Example
scalar Document @bb_scalar(_type: "Base64")

type PatientDocuments {
  id: ID!
  patient: Patient
  document: Document
Here we create a scalar type called Document and use it to store patient documents in binary format.

Void Example
scalar Void @bb_scalar(_type: "Void")

type Patient {
  id: ID!
  name: String
  dateOfBirth: Date

mutation {

  # insert a new patient record
    id: ID!
    name: String!
    dateOfBirth: Date
  ): Patient

  # update an existing patient record
    id: ID!
    name: String!
    dateOfBirth: Date
  ): Void

We've created a Void scalar type and used it to create an update for patient record. The update to the Patient will not return any data. Contrast this to the insertPatient mutation created, this returns a Patient record and you would have to specify the patient fields that you want to return when calling this mutation.

Last update: 2023-11-29