Schema

Grafbase automatically generates a GraphQL API that's deployed to the edge based on the schema defined inside your project's grafbase/schema.graphql file.

The schema is built up of built-in and custom scalars as well as directives that control validation, auth, connecting data with relations, and more.

type Post @model {
  id: ID!
  title: String!
  published: Boolean
  rating: Float
  likes: Int
  # ...
}

Grafbase does not currently support Interface or Union types.

Learn more about the @model directive.

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.

This field is automatically managed by Grafbase. Its value is most commonly used when fetching, updating, deleting, or connecting data, and not designed to be human readable. The value is typically prefixed with the model name.

type Post @model {
  id: ID!
}

You must provide the id field to all types that use the @model directive.

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 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 [email protected], 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.

type Category @model {
  # ...
  posts: [Post]
}

type Post @model {
  # ...
  category: Category
}

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