File tree Expand file tree Collapse file tree 5 files changed +77
-42
lines changed
Expand file tree Collapse file tree 5 files changed +77
-42
lines changed Original file line number Diff line number Diff line change 255255 <Compile Include =" Schema\Conventions.cs" />
256256 <Compile Include =" Types\ConnectionExtensions.cs" />
257257 <Compile Include =" Types\ConnectionWithFilterBuilder.cs" />
258+ <Compile Include =" Types\PublishedContentAtRootQuery.cs" />
259+ <Compile Include =" Types\PublishedContentQuery.cs" />
258260 <Compile Include =" Web\AppBuilderExtensions.cs" />
259261 <Compile Include =" Web\GraphQLServerOptions.cs" />
260262 <Compile Include =" Web\GraphQLMiddleware.cs" />
Original file line number Diff line number Diff line change @@ -76,29 +76,7 @@ public UmbracoSchema(
7676 RegisterTypes ( mediaTypes . ToArray ( ) ) ;
7777 // RegisterTypes(memberTypeService.GetAll().CreateGraphTypes(PublishedItemType.Member, resolveName).ToArray());
7878
79- var query = new UmbracoQuery ( ) ;
80-
81-
82-
83- foreach ( var type in documentTypes . FindAll ( x => x . GetMetadata < bool > ( "allowedAtRoot" ) ) )
84- {
85- string documentTypeAlias = type . GetMetadata < string > ( "documentTypeAlias" ) ;
86-
87- query . AddField (
88- new FieldType
89- {
90- Name = type . GetMetadata < string > ( "documentTypeAlias" ) ,
91- ResolvedType = new ListGraphType ( type ) ,
92- Resolver = new FuncFieldResolver < object > ( context =>
93- {
94- var userContext = ( UmbracoGraphQLContext ) context . UserContext ;
95- return userContext . Umbraco . TypedContentAtXPath ( $ "/root/{ documentTypeAlias } ") ;
96- } )
97- }
98- ) ;
99- }
100-
101- Query = query ;
79+ Query = new UmbracoQuery ( documentTypes ) ;
10280 }
10381
10482 public static IEnumerable < IGraphType > CreateGraphTypes (
Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+ using System . Linq ;
3+ using GraphQL . Resolvers ;
4+ using GraphQL . Types ;
5+
6+ namespace Our . Umbraco . GraphQL . Types
7+ {
8+ public class PublishedContentAtRootQuery : ObjectGraphType
9+ {
10+ public PublishedContentAtRootQuery ( IEnumerable < IGraphType > documentGraphTypes )
11+ {
12+ Name = "PublishedContentAtRootQuery" ;
13+
14+ Field < NonNullGraphType < ListGraphType < PublishedContentGraphType > > > ( )
15+ . Name ( "all" )
16+ . Resolve ( context =>
17+ {
18+ var userContext = ( UmbracoGraphQLContext ) context . UserContext ;
19+ return userContext . Umbraco . TypedContentAtRoot ( ) ;
20+ } ) ;
21+
22+ foreach ( var type in documentGraphTypes . Where ( x => x . GetMetadata < bool > ( "allowedAtRoot" ) ) )
23+ {
24+ string documentTypeAlias = type . GetMetadata < string > ( "documentTypeAlias" ) ;
25+
26+ this . AddField (
27+ new FieldType
28+ {
29+ Name = type . Name ,
30+ ResolvedType = new NonNullGraphType ( new ListGraphType ( type ) ) ,
31+ Resolver = new FuncFieldResolver < object > ( context =>
32+ {
33+ var userContext = ( UmbracoGraphQLContext ) context . UserContext ;
34+ return userContext . Umbraco . TypedContentAtXPath ( $ "/root/{ documentTypeAlias } ") ;
35+ } )
36+ }
37+ ) ;
38+ }
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+ using GraphQL . Types ;
3+
4+ namespace Our . Umbraco . GraphQL . Types
5+ {
6+ public class PublishedContentQuery : ObjectGraphType
7+ {
8+ public PublishedContentQuery ( IEnumerable < IGraphType > documentGraphTypes )
9+ {
10+ Name = "PublishedContentQuery" ;
11+
12+ Field < PublishedContentGraphType > ( )
13+ . Name ( "byId" )
14+ . Argument < NonNullGraphType < IdGraphType > > ( "id" , "The unique content id" )
15+ . Resolve ( context =>
16+ {
17+ var userContext = ( UmbracoGraphQLContext ) context . UserContext ;
18+ var id = context . GetArgument < int > ( "id" ) ;
19+ return userContext . Umbraco . TypedContent ( id ) ;
20+ } ) ;
21+
22+ Field < NonNullGraphType < PublishedContentAtRootQuery > > ( )
23+ . Name ( "atRoot" )
24+ . Resolve ( context => context . ReturnType )
25+ . Type ( new NonNullGraphType ( new PublishedContentAtRootQuery ( documentGraphTypes ) ) ) ;
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
12using GraphQL . Types ;
2- using Umbraco . Core . Models ;
33
44namespace Our . Umbraco . GraphQL . Types
55{
6-
76 public class UmbracoQuery : ObjectGraphType
87 {
9- public UmbracoQuery ( )
8+ public UmbracoQuery ( IEnumerable < IGraphType > documentTypes )
109 {
11- Field < PublishedContentGraphType > ( )
10+ Field < NonNullGraphType < PublishedContentQuery > > ( )
1211 . Name ( "content" )
13- . Argument < NonNullGraphType < IdGraphType > > ( "id" , "The unique content id" )
14- . Resolve ( context =>
15- {
16- var userContext = ( UmbracoGraphQLContext ) context . UserContext ;
17- var id = context . GetArgument < int > ( "id" ) ;
18- return userContext . Umbraco . TypedContent ( id ) ;
19- } ) ;
20-
21- Field < ListGraphType < PublishedContentGraphType > > ( )
22- . Name ( "contentAtRoot" )
23- . Resolve ( context =>
24- {
25- var userContext = ( UmbracoGraphQLContext ) context . UserContext ;
26- return userContext . Umbraco . TypedContentAtRoot ( ) ;
27- } ) ;
12+ . Resolve ( context => context . ReturnType )
13+ . Type ( new NonNullGraphType ( new PublishedContentQuery ( documentTypes ) ) ) ;
2814 }
2915 }
3016}
You can’t perform that action at this time.
0 commit comments