Skip to content

Content Queries

The Nikcio.UHeadless package provides various content queries that allow you to retrieve content items in different ways from Umbraco CMS. These queries are divided into two variations: “Basic” and “Auth” queries.

Basic Queries

The “Basic” queries do not require authorization and provide unrestricted access to CMS data. Use the following code example to add a basic content query to the UHeadless options:

.AddUHeadless(new()
{
UHeadlessGraphQLOptions = new()
{
GraphQLExtensions = (IRequestExecutorBuilder builder) =>
{
builder.UseContentQueries(); // Use this from v4.1.0+ (Only add one)
builder.AddTypeExtension<BasicContentAllQuery>();
return builder;
},
},
})

Do note that adding the code above will override the defaults and remove the contentAtRoot query. To use the contentAtRoot query, you need to add the BasicContentAtRootQuery to the options.

The following basic content queries are available:

Query class NameDescription
BasicContentAllQueryGets all the content items available.
BasicContentAtRootQueryGets all the content items at the root level.
BasicContentByAbsoluteRouteQueryGets a content item by an absolute route.
BasicContentByContentTypeQueryGets all the content items by content type.
BasicContentByGuidQueryGets a content item by GUID.
BasicContentByIdQueryGets a content item by ID.
BasicContentByTagQueryGets content items by tag.
BasicContentDescendantsByAbsoluteRouteQueryGets content item descendants by an absolute route.
BasicContentDescendantsByContentTypeQueryGets all descendants of content items with a specific content type.
BasicContentDescendantsByGuidQueryGets descendants on a content item selected by GUID.
BasicContentDescendantsByIdQueryGets descendants on a content item selected by ID.

You can explore these queries and their parameters in the UI provided at /graphql when you have added them to the UHeadlessGraphQLOptions.GraphQLExtensions like in the example above.

Auth Queries

The “Auth” queries require authentication when querying data. “Auth” queries are “Basic” queries that have been overridden and added the [Authorize] attribute from using HotChocolate.Authorization. Use the following code example to add an authenticated content query to the UHeadless options:

.AddUHeadless(new()
{
UHeadlessGraphQLOptions = new()
{
GraphQLExtensions = (IRequestExecutorBuilder builder) =>
{
builder.UseContentQueries(); // Use this from v4.1.0+ (Only add one)
builder.AddTypeExtension<AuthContentAllQuery>();
return builder;
},
},
})

Do note that adding the code above will override the defaults and remove the contentAtRoot query. To use the contentAtRoot query, you need to add the BasicContentAtRootQuery to the options.

The following authenticated content queries are available:

Query class NameDescription
AuthContentAllQueryGets all the content items available.
AuthContentAtRootQueryGets all the content items at the root level.
AuthContentByAbsoluteRouteQueryGets a content item by an absolute route.
AuthContentByContentTypeQueryGets all the content items by content type.
AuthContentByGuidQueryGets a content item by GUID.
AuthContentByIdQueryGets a content item by ID.
AuthContentByTagQueryGets content items by tag.
AuthContentDescendantsByAbsoluteRouteQueryGets content item descendants by an absolute route.
AuthContentDescendantsByContentTypeQueryGets all descendants of content items with a specific content type.
AuthContentDescendantsByGuidQueryGets descendants on a content item selected by GUID.
AuthContentDescendantsByIdQueryGets descendants on a content item selected by ID.

You can explore these queries and their parameters in the UI provided at /graphql when you have added them to the UHeadlessGraphQLOptions.GraphQLExtensions like in the example above.

Queries

Explore the most up to date information when the query is registered in your application like in the example in the sections above. Then the query information will be available at /graphql

ContentAll

Gets all the content items available.

Parameters:

  • culture: The culture.
  • preview: Fetch preview values. Preview will show unpublished items.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentAtRoot

Gets all the content items at the root level.

Parameters:

  • culture: The culture.
  • preview: Fetch preview values. Preview will show unpublished items.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentByAbsoluteRoute

Gets a content item by an absolute route.

Parameters:

  • route: The route to fetch. Example: ‘/da/frontpage/’.
  • baseUrl: The base URL for the request. Example: ‘https://my-website.com/‘. Default is the current domain.
  • culture: The culture.
  • preview: Fetch preview values. Preview will show unpublished items.
  • routeMode: Modes for requesting by route.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentByContentType

Gets all the content items by content type.

Parameters:

  • contentType: The contentType to fetch.
  • culture: The culture.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentByGuid

Gets a content item by GUID.

Parameters:

  • id: The ID to fetch.
  • culture: The culture to fetch.
  • preview: Fetch preview values. Preview will show unpublished items.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentById

Gets a content item by ID.

Parameters:

  • id: The ID to fetch.
  • culture: The culture to fetch.
  • preview: Fetch preview values. Preview will show unpublished items.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentByTag

Gets content items by tag.

Parameters:

  • tag: The tag to fetch.
  • tagGroup: The tag group to fetch.
  • culture: The culture to fetch.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentDescendantsByAbsoluteRoute

Gets content item descendants by an absolute route.

Parameters:

  • route: The route to fetch. Example: ‘/da/frontpage/’.
  • baseUrl: The base URL for the request. Example: ‘https://my-website.com/‘. Default is the current domain.
  • culture: The culture.
  • preview: Fetch preview values. Preview will show unpublished items.
  • routeMode: Modes for requesting by

route.

  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentDescendantsByContentType

Gets all descendants of content items with a specific content type.

Parameters:

  • contentType: The contentType to fetch.
  • culture: The culture.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentDescendantsByGuid

Gets descendants of a content item selected by GUID.

Parameters:

  • id: The ID to fetch.
  • culture: The culture to fetch.
  • preview: Fetch preview values. Preview will show unpublished items.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

ContentDescendantsById

Gets descendants of a content item selected by ID.

Parameters:

  • id: The ID to fetch.
  • culture: The culture to fetch.
  • preview: Fetch preview values. Preview will show unpublished items.
  • segment: The property variation segment.
  • fallback: The property value fallback strategy.

Next steps

When creating your GraphQL queries for media, the properties section can be a little difficult to wrap your head around. Therefore, you can find some documentation about how you can query this here.