Skip to content

Commit

Permalink
Merge pull request #44 from rasmusjp/feature/remove-contentdata-field
Browse files Browse the repository at this point in the history
Remove contentdata field (#42)
  • Loading branch information
rasmusjp authored Feb 11, 2019
2 parents c538eb1 + 336d128 commit a42273d
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 117 deletions.
72 changes: 24 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ Query examples based on The Starter Kit
byType {
People(id: "1116") {
pageTitle
_contentData {
children {
items {
... on Person {
_contentData {
name
}
department
photo {
_contentData {
url
}
}
_children {
items {
... on Person {
_name
department
photo {
_url
}
}
}
Expand All @@ -76,19 +70,13 @@ We can also do some simple filtering and sorting, ([Inspired by the Grahpcool fi
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
}
}
peopleStartsWithJ: _children(filter: {_name_starts_with: "J"}, orderBy: _name_ASC) {
items {
... on Person {
_name
department
photo {
_url
}
}
}
Expand All @@ -107,11 +95,9 @@ And even query for multiple types at the same time
byType {
People(id: "1116") {
pageTitle
_contentData {
peopleStartsWithJ: children(filter: {name_starts_with: "J"}, orderBy: name_ASC) {
items {
...SimplePerson
}
peopleStartsWithJ: _children(filter: {_name_starts_with: "J"}, orderBy: _name_ASC) {
items {
...SimplePerson
}
}
}
Expand All @@ -121,11 +107,9 @@ And even query for multiple types at the same time
featuredProducts {
...SimpleProduct
}
_contentData {
children {
items {
...SimpleProduct
}
_children {
items {
...SimpleProduct
}
}
}
Expand All @@ -134,27 +118,19 @@ And even query for multiple types at the same time
}

fragment SimplePerson on Person {
_contentData {
name
}
_name
department
photo {
_contentData {
url
}
_url
}
}

fragment SimpleProduct on Product {
_contentData {
name
}
_name
price
sku
photos {
_contentData {
url
}
_url
}
}
```
8 changes: 8 additions & 0 deletions src/Our.Umbraco.GraphQL/GraphQLAuthenticationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public static void SetPermissions(this FieldType type, string documentTypeAlias,
type.RequirePermission(readPermissionKey);
}

public static FieldBuilder<TSourceType, TReturnType> SetPermissions<TSourceType, TReturnType>(
this FieldBuilder<TSourceType, TReturnType> builder, GraphType graphType, bool isBuiltInProperty = false)
{
SetPermissions(builder.FieldType, graphType, isBuiltInProperty);
return builder;
}


public static void SetPermissions(this FieldType type, GraphType graphType, bool isBuiltInProperty = false)
{
// The graph type should have the doc type alias set in the meta data so we're accessing it from that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,137 @@
using System.Linq;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;

namespace Our.Umbraco.GraphQL.Types
{
internal static class ComplexGraphTypeOfIPublishedContentExtensions
{
public static ComplexGraphType<IPublishedContent> AddUmbracoBuiltInProperties(this ComplexGraphType<IPublishedContent> graphType)
{
//TODO: black/whitelist properties
graphType.Field<NonNullGraphType<DateGraphType>>()
.Name("_createDate")
.Description("Create date of the content.")
.Resolve(context => context.Source.Id)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<StringGraphType>>()
.Name("_creatorName")
.Description("Name of the content creator.")
.Resolve(context => context.Source.CreatorName)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<StringGraphType>>()
.Name("_documentTypeAlias")
.Description("Document type alias of the content.")
.Resolve(context => context.Source.DocumentTypeAlias)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<IdGraphType>>()
.Name("_id")
.Description("Unique id of the content.")
.Resolve(context => context.Source.Id)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<IntGraphType>>()
.Name("_index")
.Description("Index of the content.")
.Resolve(context => context.Source.GetIndex())
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<IntGraphType>>()
.Name("_level")
.Description("Level of the content.")
.Resolve(context => context.Source.Level)
.SetPermissions(graphType);

graphType.Field<NonNullGraphType<BooleanGraphType>>()
.Name("_isFirst")
.Description("Is the content first in the list.")
.Resolve(context => context.Source.IsFirst())
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<BooleanGraphType>>()
.Name("_isLast")
.Description("Is the content last in the list.")
.Resolve(context => context.Source.IsLast())
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<BooleanGraphType>>()
.Name("_isVisible")
.Description("Is the content visible.")
.Resolve(context => context.Source.IsVisible())
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<StringGraphType>>()
.Name("_name")
.Description("Name of the content.")
.Resolve(context => context.Source.Name)
.SetPermissions(graphType, true);

graphType.Field<PublishedContentInterfaceGraphType>()
.Name("_parent")
.Description("Parent of the content.")
.Resolve(context => context.Source.Parent)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<IntGraphType>>()
.Name("_sortOrder")
.Description("SortOrder of the content.")
.Resolve(context => context.Source.SortOrder)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<DateGraphType>>()
.Name("_updateDate")
.Description("Update date of the content.")
.Resolve(context => context.Source.UpdateDate)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<StringGraphType>>()
.Name("_url")
.Description("Url of the content.")
.Resolve(context => context.Source.Url)
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<StringGraphType>>()
.Name("_urlAbsolute")
.Description("Absolute url of the content.")
.Resolve(context => context.Source.UrlAbsolute())
.SetPermissions(graphType, true);

graphType.Field<NonNullGraphType<StringGraphType>>()
.Name("_writerName")
.Description("Name of the content writer.")
.Resolve(context => context.Source.WriterName)
.SetPermissions(graphType, true);

graphType.FilteredConnection<PublishedContentInterfaceGraphType, IPublishedContent>()
.Name("_ancestors")
.Description("Ancestors of the content.")
.Argument<BooleanGraphType>("includeSelf", "include self in list")
.Bidirectional()
.Resolve(context =>
(context.GetArgument<bool?>("includeSelf") == true
? context.Source.AncestorsOrSelf()
: context.Source.Ancestors()).Filter(context).ToConnection(context)
);

graphType.FilteredConnection<PublishedContentInterfaceGraphType, IPublishedContent>()
.Name("_siblings")
.Description("Siblings of the content.")
.Bidirectional()
.Resolve(context => context.Source.Siblings().Filter(context).ToConnection(context));

graphType.FilteredConnection<PublishedContentInterfaceGraphType, IPublishedContent>()
.Name("_children")
.Description("Children of the content.")
.Bidirectional()
.Resolve(context => context.Source.Children.Filter(context).ToConnection(context));

return graphType;
}

public static ComplexGraphType<IPublishedContent> AddUmbracoContentPropeties(
this ComplexGraphType<IPublishedContent> graphType,
IContentTypeComposition contentType,
Expand Down Expand Up @@ -60,7 +186,7 @@ private static IGraphQLValueResolver GetValueResolver(IContentTypeComposition co
var foundResolvers = GraphQLValueResolversResolver.Current.Resolvers.Where(r => r.IsResolver(propertyType)).ToList();
var defaultResolvers = GraphQLValueResolversResolver.Current.DefaultResolvers;

if(foundResolvers.Count == 1)
if (foundResolvers.Count == 1)
{
return foundResolvers[0];
}
Expand Down
55 changes: 0 additions & 55 deletions src/Our.Umbraco.GraphQL/Types/PublishedContentDataGraphType.cs

This file was deleted.

8 changes: 1 addition & 7 deletions src/Our.Umbraco.GraphQL/Types/PublishedContentGraphType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ public PublishedContentGraphType(IContentTypeComposition contentType, PublishedI
}
}

// TODO: set this field name as a reserved property alias
Field<NonNullGraphType<PublishedContentDataGraphType>>()
.Name("_contentData")
.Description("Built in published content data.")
.Resolve(context => context.Source)
.SetDoctypeMetadata(GetMetadata<string>(Constants.Metadata.ContentTypeAlias));

this.AddUmbracoBuiltInProperties();
this.AddUmbracoContentPropeties(contentType, itemType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ public PublishedContentInterfaceGraphType()
{
Name = "PublishedContent";

// TODO: set this field name as a reserved property alias
Field<NonNullGraphType<PublishedContentDataGraphType>>()
.Name("_contentData")
.Description("Built in published content data.")
.Resolve(context => context.Source)
.SetDoctypeMetadata(GetMetadata<string>(Constants.Metadata.ContentTypeAlias));
this.AddUmbracoBuiltInProperties();
}
}
}

0 comments on commit a42273d

Please sign in to comment.