Skip to content

Commit a42273d

Browse files
authored
Merge pull request #44 from rasmusjp/feature/remove-contentdata-field
Remove contentdata field (#42)
2 parents c538eb1 + 336d128 commit a42273d

6 files changed

+161
-117
lines changed

README.md

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,13 @@ Query examples based on The Starter Kit
4545
byType {
4646
People(id: "1116") {
4747
pageTitle
48-
_contentData {
49-
children {
50-
items {
51-
... on Person {
52-
_contentData {
53-
name
54-
}
55-
department
56-
photo {
57-
_contentData {
58-
url
59-
}
60-
}
48+
_children {
49+
items {
50+
... on Person {
51+
_name
52+
department
53+
photo {
54+
_url
6155
}
6256
}
6357
}
@@ -76,19 +70,13 @@ We can also do some simple filtering and sorting, ([Inspired by the Grahpcool fi
7670
byType {
7771
People(id: "1116") {
7872
pageTitle
79-
_contentData {
80-
peopleStartsWithJ: children(filter: {name_starts_with: "J"}, orderBy: name_ASC) {
81-
items {
82-
... on Person {
83-
_contentData {
84-
name
85-
}
86-
department
87-
photo {
88-
_contentData {
89-
url
90-
}
91-
}
73+
peopleStartsWithJ: _children(filter: {_name_starts_with: "J"}, orderBy: _name_ASC) {
74+
items {
75+
... on Person {
76+
_name
77+
department
78+
photo {
79+
_url
9280
}
9381
}
9482
}
@@ -107,11 +95,9 @@ And even query for multiple types at the same time
10795
byType {
10896
People(id: "1116") {
10997
pageTitle
110-
_contentData {
111-
peopleStartsWithJ: children(filter: {name_starts_with: "J"}, orderBy: name_ASC) {
112-
items {
113-
...SimplePerson
114-
}
98+
peopleStartsWithJ: _children(filter: {_name_starts_with: "J"}, orderBy: _name_ASC) {
99+
items {
100+
...SimplePerson
115101
}
116102
}
117103
}
@@ -121,11 +107,9 @@ And even query for multiple types at the same time
121107
featuredProducts {
122108
...SimpleProduct
123109
}
124-
_contentData {
125-
children {
126-
items {
127-
...SimpleProduct
128-
}
110+
_children {
111+
items {
112+
...SimpleProduct
129113
}
130114
}
131115
}
@@ -134,27 +118,19 @@ And even query for multiple types at the same time
134118
}
135119

136120
fragment SimplePerson on Person {
137-
_contentData {
138-
name
139-
}
121+
_name
140122
department
141123
photo {
142-
_contentData {
143-
url
144-
}
124+
_url
145125
}
146126
}
147127

148128
fragment SimpleProduct on Product {
149-
_contentData {
150-
name
151-
}
129+
_name
152130
price
153131
sku
154132
photos {
155-
_contentData {
156-
url
157-
}
133+
_url
158134
}
159135
}
160136
```

src/Our.Umbraco.GraphQL/GraphQLAuthenticationExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public static void SetPermissions(this FieldType type, string documentTypeAlias,
7777
type.RequirePermission(readPermissionKey);
7878
}
7979

80+
public static FieldBuilder<TSourceType, TReturnType> SetPermissions<TSourceType, TReturnType>(
81+
this FieldBuilder<TSourceType, TReturnType> builder, GraphType graphType, bool isBuiltInProperty = false)
82+
{
83+
SetPermissions(builder.FieldType, graphType, isBuiltInProperty);
84+
return builder;
85+
}
86+
87+
8088
public static void SetPermissions(this FieldType type, GraphType graphType, bool isBuiltInProperty = false)
8189
{
8290
// The graph type should have the doc type alias set in the meta data so we're accessing it from that

src/Our.Umbraco.GraphQL/Types/ComplexGraphTypeOfIPublishedContentExtensions.cs

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,137 @@
55
using System.Linq;
66
using Umbraco.Core.Models;
77
using Umbraco.Core.Models.PublishedContent;
8+
using Umbraco.Web;
89

910
namespace Our.Umbraco.GraphQL.Types
1011
{
1112
internal static class ComplexGraphTypeOfIPublishedContentExtensions
1213
{
14+
public static ComplexGraphType<IPublishedContent> AddUmbracoBuiltInProperties(this ComplexGraphType<IPublishedContent> graphType)
15+
{
16+
//TODO: black/whitelist properties
17+
graphType.Field<NonNullGraphType<DateGraphType>>()
18+
.Name("_createDate")
19+
.Description("Create date of the content.")
20+
.Resolve(context => context.Source.Id)
21+
.SetPermissions(graphType, true);
22+
23+
graphType.Field<NonNullGraphType<StringGraphType>>()
24+
.Name("_creatorName")
25+
.Description("Name of the content creator.")
26+
.Resolve(context => context.Source.CreatorName)
27+
.SetPermissions(graphType, true);
28+
29+
graphType.Field<NonNullGraphType<StringGraphType>>()
30+
.Name("_documentTypeAlias")
31+
.Description("Document type alias of the content.")
32+
.Resolve(context => context.Source.DocumentTypeAlias)
33+
.SetPermissions(graphType, true);
34+
35+
graphType.Field<NonNullGraphType<IdGraphType>>()
36+
.Name("_id")
37+
.Description("Unique id of the content.")
38+
.Resolve(context => context.Source.Id)
39+
.SetPermissions(graphType, true);
40+
41+
graphType.Field<NonNullGraphType<IntGraphType>>()
42+
.Name("_index")
43+
.Description("Index of the content.")
44+
.Resolve(context => context.Source.GetIndex())
45+
.SetPermissions(graphType, true);
46+
47+
graphType.Field<NonNullGraphType<IntGraphType>>()
48+
.Name("_level")
49+
.Description("Level of the content.")
50+
.Resolve(context => context.Source.Level)
51+
.SetPermissions(graphType);
52+
53+
graphType.Field<NonNullGraphType<BooleanGraphType>>()
54+
.Name("_isFirst")
55+
.Description("Is the content first in the list.")
56+
.Resolve(context => context.Source.IsFirst())
57+
.SetPermissions(graphType, true);
58+
59+
graphType.Field<NonNullGraphType<BooleanGraphType>>()
60+
.Name("_isLast")
61+
.Description("Is the content last in the list.")
62+
.Resolve(context => context.Source.IsLast())
63+
.SetPermissions(graphType, true);
64+
65+
graphType.Field<NonNullGraphType<BooleanGraphType>>()
66+
.Name("_isVisible")
67+
.Description("Is the content visible.")
68+
.Resolve(context => context.Source.IsVisible())
69+
.SetPermissions(graphType, true);
70+
71+
graphType.Field<NonNullGraphType<StringGraphType>>()
72+
.Name("_name")
73+
.Description("Name of the content.")
74+
.Resolve(context => context.Source.Name)
75+
.SetPermissions(graphType, true);
76+
77+
graphType.Field<PublishedContentInterfaceGraphType>()
78+
.Name("_parent")
79+
.Description("Parent of the content.")
80+
.Resolve(context => context.Source.Parent)
81+
.SetPermissions(graphType, true);
82+
83+
graphType.Field<NonNullGraphType<IntGraphType>>()
84+
.Name("_sortOrder")
85+
.Description("SortOrder of the content.")
86+
.Resolve(context => context.Source.SortOrder)
87+
.SetPermissions(graphType, true);
88+
89+
graphType.Field<NonNullGraphType<DateGraphType>>()
90+
.Name("_updateDate")
91+
.Description("Update date of the content.")
92+
.Resolve(context => context.Source.UpdateDate)
93+
.SetPermissions(graphType, true);
94+
95+
graphType.Field<NonNullGraphType<StringGraphType>>()
96+
.Name("_url")
97+
.Description("Url of the content.")
98+
.Resolve(context => context.Source.Url)
99+
.SetPermissions(graphType, true);
100+
101+
graphType.Field<NonNullGraphType<StringGraphType>>()
102+
.Name("_urlAbsolute")
103+
.Description("Absolute url of the content.")
104+
.Resolve(context => context.Source.UrlAbsolute())
105+
.SetPermissions(graphType, true);
106+
107+
graphType.Field<NonNullGraphType<StringGraphType>>()
108+
.Name("_writerName")
109+
.Description("Name of the content writer.")
110+
.Resolve(context => context.Source.WriterName)
111+
.SetPermissions(graphType, true);
112+
113+
graphType.FilteredConnection<PublishedContentInterfaceGraphType, IPublishedContent>()
114+
.Name("_ancestors")
115+
.Description("Ancestors of the content.")
116+
.Argument<BooleanGraphType>("includeSelf", "include self in list")
117+
.Bidirectional()
118+
.Resolve(context =>
119+
(context.GetArgument<bool?>("includeSelf") == true
120+
? context.Source.AncestorsOrSelf()
121+
: context.Source.Ancestors()).Filter(context).ToConnection(context)
122+
);
123+
124+
graphType.FilteredConnection<PublishedContentInterfaceGraphType, IPublishedContent>()
125+
.Name("_siblings")
126+
.Description("Siblings of the content.")
127+
.Bidirectional()
128+
.Resolve(context => context.Source.Siblings().Filter(context).ToConnection(context));
129+
130+
graphType.FilteredConnection<PublishedContentInterfaceGraphType, IPublishedContent>()
131+
.Name("_children")
132+
.Description("Children of the content.")
133+
.Bidirectional()
134+
.Resolve(context => context.Source.Children.Filter(context).ToConnection(context));
135+
136+
return graphType;
137+
}
138+
13139
public static ComplexGraphType<IPublishedContent> AddUmbracoContentPropeties(
14140
this ComplexGraphType<IPublishedContent> graphType,
15141
IContentTypeComposition contentType,
@@ -60,7 +186,7 @@ private static IGraphQLValueResolver GetValueResolver(IContentTypeComposition co
60186
var foundResolvers = GraphQLValueResolversResolver.Current.Resolvers.Where(r => r.IsResolver(propertyType)).ToList();
61187
var defaultResolvers = GraphQLValueResolversResolver.Current.DefaultResolvers;
62188

63-
if(foundResolvers.Count == 1)
189+
if (foundResolvers.Count == 1)
64190
{
65191
return foundResolvers[0];
66192
}

src/Our.Umbraco.GraphQL/Types/PublishedContentDataGraphType.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/Our.Umbraco.GraphQL/Types/PublishedContentGraphType.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ public PublishedContentGraphType(IContentTypeComposition contentType, PublishedI
3030
}
3131
}
3232

33-
// TODO: set this field name as a reserved property alias
34-
Field<NonNullGraphType<PublishedContentDataGraphType>>()
35-
.Name("_contentData")
36-
.Description("Built in published content data.")
37-
.Resolve(context => context.Source)
38-
.SetDoctypeMetadata(GetMetadata<string>(Constants.Metadata.ContentTypeAlias));
39-
33+
this.AddUmbracoBuiltInProperties();
4034
this.AddUmbracoContentPropeties(contentType, itemType);
4135
}
4236
}

src/Our.Umbraco.GraphQL/Types/PublishedContentInterfaceGraphType.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ public PublishedContentInterfaceGraphType()
1111
{
1212
Name = "PublishedContent";
1313

14-
// TODO: set this field name as a reserved property alias
15-
Field<NonNullGraphType<PublishedContentDataGraphType>>()
16-
.Name("_contentData")
17-
.Description("Built in published content data.")
18-
.Resolve(context => context.Source)
19-
.SetDoctypeMetadata(GetMetadata<string>(Constants.Metadata.ContentTypeAlias));
14+
this.AddUmbracoBuiltInProperties();
2015
}
2116
}
2217
}

0 commit comments

Comments
 (0)