An experimental implementation of GraphQL for Umbraco using GraphQL for .NET.
If you're interested in getting GraphQL into Umbraco Core please join the discussion on Our and on the issue tracker.
Please note this should not be used in production, since there are no security and all you data will be publicly available.
An Owin middleware exposes Umbraco Published Content as a GraphQL endpoint.
GraphQL types are dynamically generated for all Umbraco document types (content and media), with all the properties as fields. They all implement an interface PublishedContent
which implements the generic Umbraco properties as fields.
The preferred way to install GraphQL for Umbraco is through NuGet
GraphQL for Umbraco is available as a NuGet package.
To install run the following command in the Package Manager Console
PM> Install-Package Our.Umbraco.GraphQL
Clone the repository and run the Website (F5 in Visual Studio), install Umbraco with the starter kit and start exploring the API using GraphiQL by opening /umbraco/graphiql
.
Url | Description |
---|---|
/umbraco/graphiql | GraphiQL interface |
/umbraco/graphql | GraphQL endpoint |
/umbraco/graphql/schema | The generated schema |
Query examples based on The Starter Kit
{
content {
byType {
People(id: "1116") {
pageTitle
_contentData {
children {
items {
... on Person {
_contentData {
name
}
department
photo {
_contentData {
url
}
}
}
}
}
}
}
}
}
}
We can also do some simple filtering and sorting, (Inspired by the Grahpcool filtering) like geting all children of people that starts with the letter J
{
content {
byType {
People(id: "1116") {
pageTitle
_contentData {
peopleStartsWithJ: children(filter: {name_starts_with: "J"}, orderBy: name_ASC) {
items {
... on Person {
_contentData {
name
}
department
photo {
_contentData {
url
}
}
}
}
}
}
}
}
}
}
And even query for multiple types at the same time
{
content {
byType {
People(id: "1116") {
pageTitle
_contentData {
peopleStartsWithJ: children(filter: {name_starts_with: "J"}, orderBy: name_ASC) {
items {
...SimplePerson
}
}
}
}
Products(id: "1107") {
pageTitle
defaultCurrency
featuredProducts {
...SimpleProduct
}
_contentData {
children {
items {
...SimpleProduct
}
}
}
}
}
}
}
fragment SimplePerson on Person {
_contentData {
name
}
department
photo {
_contentData {
url
}
}
}
fragment SimpleProduct on Product {
_contentData {
name
}
price
sku
photos {
_contentData {
url
}
}
}