Queries

Grafbase automatically generates queries to fetch entries by ID or by collection, based on the types you define in your schema.

Grafbase generates a query in the format of the model name, camelCased, for all types in your schema tagged with @model directive.

The response type is in the format of [modelName].

type Post @model {
  id: ID!
  title: String
}

When fetching individual items from your backend you can use the following arguments:

  • id: ID! — The id of the entry you're requesting.
type Post @model {
  # ...
  title: String
}

Grafbase generates a query in the format of [modelName]Collection, camelCased for all types tagged with a @model directive.

The response type is in the format of [modelName]Connection.

type Post @model {
  id: ID!
  title: String
}

Collection queries contain the following optional arguments to aid things like pagination:

  • after: String
  • before: String
  • first: Int
  • last: Int
type Post @model {
  # ...
  title: String
}

Learn more about pagination and connections.

If your schema contains multiple, related types, you can query for those at the same time you request the parent/child.

type Post @model {
  id: ID!
  title: String!
  category: Category
}

type Category {
  id ID!
  name: String!
  posts: [Post]
}