Scalars
Grafbase supports multiple field types. GraphQL calls these "scalars".
Grafbase supports the typical scalars you'd expect from any GraphQL implementation, as well as some custom ones. All scalars behave differently when mutating and querying depending on the data they represent.
All nullable fields default to null
unless marked as non nullable.
The ID
scalar represents a unique identifier for the data it represents. This field works in the same way as a String
does.
type Post @model {
customIdField: ID!
}
The String
scalar represents a UTF-8 character sequence.
type Post @model {
title: String
}
The Int
scalar represents a signed, 32-bit integer, which can be positive, negative, or 0
.
type Post @model {
likes: Int
}
The Float
scalar represents a signed, double-precision floating-point value, which can be positive, negative, or 0
.
type Post @model {
rating: Float
}
The Boolean
scalar represents a true
or false
value for non-nullable fields. Nullable fields default to null
.
type Post @model {
published: Boolean
}
The Date
scalar represents a date in the format of 2022-11-07
as described in RFC3339.
type User @model {
dob: Date
}
The DateTime
scalar represents a date and a time in RFC3339 format.
type Post @model {
publishedOn: DateTime
}
The Email
scalar represents an email address in the typical format of hello@grafbase.com
, following the HTML Spec.
type User @model {
email: Email
}
The IPAddress
scalar represents a valid IPv4 or IPv6 address, with optional CIDR. IPv4 addresses are expected in quad-dotted notation, such as 123.123.123.123
.
IPv6 addresses are expected in non-bracketed, colon-separated format, such as 1a2b:3c4b::1234:4567
.
type Activity @model {
ip: IPAddress
}
The Timestamp
scalar represents a unix epoch time, in milliseconds.
type Activity @model {
when: Timestamp
}
The URL
scalar represents a URL standard value, in the format of (but not limited to) http://
, https://
, wss://
.
type User @model {
avatarUrl: URL
}
The JSON
scalar represents a JSON object that follows the ECMA-404 specification.
type Order @model {
metadata: JSON
}
The PhoneNumber
scalar represents a E.164 phone number value, with or without the country code.
type User @model {
contactNo: PhoneNumber
}
Grafbase supports using other models as types in the format of a relation. Supported relations are one to one, one to many, many to one, and many to many.
type User @model {
name: String
profile: Profile
}
type Profile @model {
bio: String
user: User
}
Grafbase supports the notion of non-nullable types. This means Grafbase promises to always give you a value when you query this field, and you must provide a value when a field is set as non-nullable.
type User @model {
name: String!
}
Grafbase supports using list values whereby multiple scalars can be used as values for fields.
type Post @model {
keywords: [String]
}
Grafbase supports using non-nullable list values whereby multiple scalars can be used as values for fields.
type Post @model {
keywords: [String!]!
}
You can use enums specified in your schema as field types.
type Post @model {
status: Status
}
enum Status {
PENDING_REVIEW
APPROVED
}