Skip to content

Commit 9140c1a

Browse files
Merge pull request #23 from rasmusjp/feature/query-by-url
Add by url query
2 parents fc19d52 + bd5206d commit 9140c1a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ public PublishedContentQuery(IEnumerable<IGraphType> documentGraphTypes)
1919
return userContext.Umbraco.TypedContent(id);
2020
});
2121

22+
Field<PublishedContentGraphType>()
23+
.Name("byUrl")
24+
.Argument<NonNullGraphType<StringGraphType>>("url", "The relative content url")
25+
.Resolve(context =>
26+
{
27+
var userContext = context.UmbracoUserContext();
28+
var url = context.GetArgument<string>("url");
29+
30+
var pcr = new PublishedContentRequest(
31+
new Uri(userContext.RequestUri, url),
32+
userContext.UmbracoContext.RoutingContext,
33+
UmbracoConfig.For.UmbracoSettings().WebRouting,
34+
null
35+
);
36+
37+
pcr.Prepare();
38+
39+
if (pcr.IsRedirect || pcr.IsRedirectPermanent || pcr.Is404)
40+
{
41+
return null;
42+
}
43+
44+
return pcr.PublishedContent;
45+
});
46+
2247
Field<NonNullGraphType<PublishedContentAtRootQuery>>()
2348
.Name("byType")
2449
.Resolve(context => context.ReturnType)

0 commit comments

Comments
 (0)