|
5 | 5 | using System.Linq;
|
6 | 6 | using Umbraco.Core.Models;
|
7 | 7 | using Umbraco.Core.Models.PublishedContent;
|
| 8 | +using Umbraco.Web; |
8 | 9 |
|
9 | 10 | namespace Our.Umbraco.GraphQL.Types
|
10 | 11 | {
|
11 | 12 | internal static class ComplexGraphTypeOfIPublishedContentExtensions
|
12 | 13 | {
|
| 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 | + |
13 | 139 | public static ComplexGraphType<IPublishedContent> AddUmbracoContentPropeties(
|
14 | 140 | this ComplexGraphType<IPublishedContent> graphType,
|
15 | 141 | IContentTypeComposition contentType,
|
@@ -60,7 +186,7 @@ private static IGraphQLValueResolver GetValueResolver(IContentTypeComposition co
|
60 | 186 | var foundResolvers = GraphQLValueResolversResolver.Current.Resolvers.Where(r => r.IsResolver(propertyType)).ToList();
|
61 | 187 | var defaultResolvers = GraphQLValueResolversResolver.Current.DefaultResolvers;
|
62 | 188 |
|
63 |
| - if(foundResolvers.Count == 1) |
| 189 | + if (foundResolvers.Count == 1) |
64 | 190 | {
|
65 | 191 | return foundResolvers[0];
|
66 | 192 | }
|
|
0 commit comments