Cedalio
Search
K

Scalars

Cedalio offers support for various field types, known as "scalars," in GraphQL terminology.

Scalars

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.

ID

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!
}

String

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!"
}
}
}
}

Int

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
}
}
}
}

Float

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
}
}
}
}

Boolean

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
}
}
}
}

Date

The Date scalar represents a date in the format of 2023-07-25 as described in RFC3339.
schema.graphql
type User @model {
dob: Date
}
mutation {
userCreate(input: { dob: "2023-07-25" }) {
dob
}
}
{
"data": {
"postCreate": {
"post": {
"dob": "2023-07-25"
}
}
}
}

DateTime

The DateTime scalar represents a date and a time in RFC3339 format.
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"
}
}
}
}

Email

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]"
}
}
}
}

IPAddress

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
}

Timestamp

The Timestamp scalar represents a unix epoch time, in milliseconds.
SchemaExample
schema.graphql
type Activity @model {
when: Timestamp
}
mutation {
activityCreate(input: { when: 1662032540 }) {
when
}
}
{
"data": {
"activityCreate": {
"activity": {
"when": 1662032540
}
}
}
}

URL

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
}

JSON

The JSON scalar represents a JSON object that follows the ECMA-404 specification.
SchemaExample
type Order @model {
metadata: JSON
}

PhoneNumber

The PhoneNumber scalar represents a E.164 phone number value, with or without the country code.
SchemaExample
type User @model {
contactNo: PhoneNumber
}

Relations

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]
}
Learn more about Relations.

Non-nullable types

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!
}

Lists

Cedalio supports using list values whereby multiple scalars can be used as values for fields.
SchemaExample
type Post @model {
keywords: [String]
}

Non-nullable lists

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!]!
}

Enumerations

You can use enums specified in your schema as field types.
SchemaExample
type Post @model {
status: Status
}
enum Status {
PENDING_REVIEW
APPROVED
}
Learn more about Enums.