Skip to content

Commit 0ab4d0e

Browse files
committed
Move fields from _contentData to PublishedContent and prefix with _
1 parent c538eb1 commit 0ab4d0e

File tree

5 files changed

+137
-69
lines changed

5 files changed

+137
-69
lines changed

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)