URL
Even in the world of headless content creation a large portion of that content is being delivered through the Web. Codex is designed to provide an intuitive and productive developer experience for content that is going to be develivered through the web. This experience is achieved by offering a range of features for managing and delivering content to end users while keeping in mind good user esperience (web core vitals) and search engine optimization.
A crucial part of delivering content to end users through the web is the URL. With Codex you can use the native Codex URL field which provides automatic and manual URL generating based on different parameters and configurations.
On top of the URLs generated, the Codex GraphQL API out of the box URL resolving for the content created in Admin. By using the Codex URl resolver, you don't have to create special routing configurations in your front ends, or implement some kind of reverse lookups between slugs and IDs. All of this is supported natively through the API, just send the relative URL and we will return the content that you need. All you have to do is configure the patterns of URLs for content models that you create and implement how you want to display that content to end users. Codex takes care of the rest.
Resolving the entity
To resolve the entity you should send the relative URL to the resolveURL field in root Query
query {
resovleURL (url: "/docs/graphql/urls") {
...select the data you need here
}
}
The resolver returns a URL entity which is a union that can resolve to a Codex Section, CodexAuthor or any of model types that contain a Codex URL field.
union UrlEntity =
CodexSection
| CodexAuthor
| ...other model types
Example
Let's take the two models as an example from our schema documentation and add a field "url" to both of them. The "url" field is Codex URL native fields which resolved to a String. In admin you can configure how this field is generated or written manually by editors.
type Restaurant implements CodexEntry {
id: String!
name: String
address: CodexLocation
image: CodexMedia
startHour: Int
endHour: Int
hasDelivery: Boolean
url: String
system: CodexSystem
attrs: Json
relations: RestaurantRelations
}
type Recipe implements CodexEntry {
id: String!
title: String
timeToCook: Int
tags: [String]
restaurant: Reference
image: Media
parameters: Json
url: String
restaurant: Restaurant
system: CodexSystem
attrs: Json
relations: RecipeRelations
}
In your front ends you can call perform the resolveURL query in the GraphQL API and based on the URLEntity type you can display the restaurant or recipe to the end users.
query {
resolveURL (url: "/propper-pizza") {
__typename
...on Restaurant {
id
name
hasDelivery
}
...on Recipe {
id
title
timeToCook
tags
restaurant {
id
name
hasDelivery
}
}
}
}
The above query would result in something like this
{
"data": {
"resolveURL": {
"__typename": "Restaurant",
"id": "restaurant-entry-id",
"name": "restaurant-name",
"hasDelivery": true
}
}
}