Cedalio
Search
K

Queries

Cedalio automatically creates queries for retrieving entries based on their ID, unique field, or by collection, according to the types defined in your schema.

Fetch by

Cedalio generates a query for all types in your schema tagged with the @model directive.
The generated query contains a single by argument to fetch a record by id, or by @unique field.
  • by: [modelName]ByInput! — The input [modelName]ByInput type contains id, and all other unique fields of that the @model.
The query returns the type [modelName].
Schema
Generated types
Fetch by ID
Fetch by unique
type Post @model {
title: String
slug: String! @unique
}
type Post {
id: ID!
title: String
slug: String!
}
type Query {
post(by: PostByInput!): Post
}
input PostByInput {
id: ID
slug: String
}
query {
post(by: { id: "post_000000000AAAAAAAAAAA" }) {
title
}
}
query {
post(by: { slug: "hello-Cedalio" }) {
id
slug
title
}
}

Fetch by collection

Cedalio 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].
Schema
Generated types
Query
Response
type Post @model {
title: String
}
type Post {
id: ID!
title: String
}
type Query {
postCollection(
after: String
before: String
first: Int
last: Int
orderBy: PostOrderByInput
): PostConnection
}
type PostConnection {
edges: [PostEdge]
pageInfo: PageInfo!
}
type PostEdge {
cursor: String!
node: Post!
}
type PageInfo {
endCursor: String
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
}
type PostOrderByInput {
createdAt: OrderByDirection
}
enum OrderByDirection {
ASC
DESC
}
query {
postCollection(first: 100) {
edges {
node {
title
}
}
}
}
{
"data": {
"postCollection": {
"edges": [
{
"node": {
"title": "Hello Cedalio"
}
}
]
}
}
}

Fetch by collection arguments

Collection queries contain the following optional arguments to aid things like pagination and ordering:
  • after: String
  • before: String
  • first: Int
  • last: Int
  • orderBy: PostOrderByInput
Schema
Fetch first 3
Fetch first 3 after cursor
Fetch last 3 before cursor
Fetch first 10 order by DESC creation date
type Post @model {
title: String
}
query {
postCollection(first: 3) {
edges {
cursor
node {
title
}
}
}
}
query {
postCollection(first: 3, after: "post_01GCYG0VT9RKB6K4ZSTVABKH03") {
edges {
cursor
node {
title
}
}
}
}
query {
postCollection(last: 3, before: "post_01GCYG0VT9RKB6K4ZSTVABKH03") {
edges {
cursor
node {
title
}
}
}
}
query {
postCollection(first: 10, orderBy: { createdAt: DESC }) {
edges {
cursor
node {
title
}
}
}
}a

Relations

If your schema contains multiple, related types, you can query for those at the same time you request the parent/child.
Schema
Generated types
Get posts by category
type Post @model {
title: String!
category: Category
}
type Category @model {
name: String!
posts: [Post]
}
type Post {
title: String!
category: Category
}
type Category {
name: String!
posts: [Post]
}
query {
category(by: { id: "category_01GD0BQFPMD8ARK4C9AX14YQCT" }) {
name
posts(first: 2) {
edges {
node {
title
}
}
}
}
}