Scalars
Cedalio offers support for various field types, known as "scalars," in GraphQL terminology.
Cedalio provides the standard scalars commonly found in GraphQL implementations, along with additional custom scalars. Each scalar behaves differently during mutation and querying, depending on the type of data it represents.
By default, all fields are nullable and hold a value of
null
unless explicitly 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.schema.graphql
type Post @model {
customIdField: ID!
}
The
String
scalar represents a UTF-8 character sequence.schema.graphql
type Post @model {
title: String
}
mutation {
postCreate(input: { title: "Hello Cedalio!" }) {
title
}
}
{
"data": {
"postCreate": {
"post": {
"title": "Hello Cedalio!"
}
}
}
}
The
Int
scalar represents a signed, 32-bit integer, which can be positive, negative, or 0
.SchemaExample
schema.graphql
type Post @model {
likes: Int
}
mutation {
postCreate(input: { likes: 10 }) {
likes
}
}
{
"data": {
"postCreate": {
"post": {
"likes": 10
}
}
}
}
The
Float
scalar represents a signed, double-precision floating-point value, which can be positive, negative, or 0
.schema.graphql
type Post @model {
rating: Float
}
mutation {
postCreate(input: { rating: 9.5 }) {
rating
}
}
{
"data": {
"postCreate": {
"post": {
"rating": 9.5
}
}
}
}
The
Boolean
scalar represents a true
or false
value for non-nullable fields. Nullable fields default to null
.schema.graphql
type Post @model {
published: Boolean
}
mutation {
postCreate(input: { published: true }) {
published
}
}
{
"data": {
"postCreate": {
"post": {
"published": true
}
}
}
}
schema.graphql
type User @model {
dob: Date
}
mutation {
userCreate(input: { dob: "2023-07-25" }) {
dob
}
}
{
"data": {
"postCreate": {
"post": {
"dob": "2023-07-25"
}
}
}
}
schema.graphql
type Post @model {
publishedOn: DateTime
}
mutation {
postCreate(input: { publishedOn: "2023-07-25T10:00:00+01:00" }) {
publishedOn
}
}
{
"data": {
"postCreate": {
"post": {
"publishedOn": "2023-07-25T10:00:00+01:00"
}
}
}
}
The
Email
scalar represents an email address in the typical format of [email protected]
, following the HTML Spec.schema.graphql
type User @model {
email: Email
}
mutation {
userCreate(input: { email: "[email protected]" }) {
email
}
}
{
"data": {
"userCreate": {
"user": {
"email": "[email protected]"
}
}
}
}
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
.SchemaIPv4 ExampleIPv6 Example
type Activity @model {
ip: IPAddress
}
SchemaExample
schema.graphql
type Activity @model {
when: Timestamp
}
mutation {
activityCreate(input: { when: 1662032540 }) {
when
}
}
{
"data": {
"activityCreate": {
"activity": {
"when": 1662032540
}
}
}
}
The
URL
scalar represents a URL standard value, in the format of (but not limited to) http://
, https://
, wss://
.SchemaExample
type User @model {
avatarUrl: URL
}
SchemaExample
type Order @model {
metadata: JSON
}
SchemaExample
type User @model {
contactNo: PhoneNumber
}
Cedalio 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.
OneToOne.graphql
type User @model {
name: String
profile: Profile
}
type Profile @model {
bio: String
user: User
}
OneToMany.graphql
type User @model {
posts: [Post]
}
type Post @model {
author: User
}
ManyToMany.graphql
type User @model {
posts: [Post]
}
type Post @model {
authors: [User]
}
Cedalio supports the notion of non-nullable types. This means Cedalio 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.
SchemaValid ExampleInvalid Example
type User @model {
name: String!
}
Cedalio supports using list values whereby multiple scalars can be used as values for fields.
SchemaExample
type Post @model {
keywords: [String]
}
Cedalio supports using non-nullable list values whereby multiple scalars can be used as values for fields.
SchemaValid ExampleValid Example 2Invalid ExampleInvalid Example 2
type Post @model {
keywords: [String!]!
}
You can use enums specified in your schema as field types.
SchemaExample
type Post @model {
status: Status
}
enum Status {
PENDING_REVIEW
APPROVED
}
Last modified 5mo ago