Skip to content

Commit 8d23072

Browse files
committed
.
1 parent 36054a6 commit 8d23072

15 files changed

Lines changed: 1988 additions & 1 deletion

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_ProjectedSimplified.cs

Lines changed: 992 additions & 0 deletions
Large diffs are not rendered by default.

src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,4 +732,98 @@ public FieldBuilder<TSource, IEnumerable<TReturn>> AddProjectedQueryField<TEntit
732732
GraphQlService.AddProjectedQueryField(this, name, resolve, projection, transform, itemGraphType, omitQueryArguments);
733733

734734
#endregion
735+
736+
#region Simplified API - AddProjectedField (navigation projection from TSource)
737+
738+
/// <summary>
739+
/// Adds a field that projects from the source entity and transforms the result.
740+
/// Simplified API - projection is directly from TSource.
741+
/// </summary>
742+
/// <example>
743+
/// AddProjectedField(
744+
/// name: "childName",
745+
/// projection: parent => parent.Child.Name,
746+
/// transform: name => name.ToUpper())
747+
/// </example>
748+
public FieldBuilder<TSource, TReturn> AddProjectedField<TProjection, TReturn>(
749+
string name,
750+
Expression<Func<TSource, TProjection>> projection,
751+
Func<TProjection, TReturn> transform,
752+
Type? graphType = null)
753+
where TReturn : class =>
754+
GraphQlService.AddProjectedField(this, name, projection, transform, graphType);
755+
756+
public FieldBuilder<TSource, TReturn> AddProjectedField<TProjection, TReturn>(
757+
string name,
758+
Expression<Func<TSource, TProjection>> projection,
759+
Func<TProjection, Task<TReturn>> transform,
760+
Type? graphType = null)
761+
where TReturn : class =>
762+
GraphQlService.AddProjectedField(this, name, projection, transform, graphType);
763+
764+
#endregion
765+
766+
#region Simplified API - AddProjectedListField (list projection from TSource)
767+
768+
/// <summary>
769+
/// Adds a field that projects a list from the source entity and transforms each item.
770+
/// Simplified API - projection is directly from TSource.
771+
/// </summary>
772+
/// <example>
773+
/// AddProjectedListField(
774+
/// name: "childNames",
775+
/// projection: parent => parent.Children.Select(c => c.Name),
776+
/// transform: name => name.ToUpper())
777+
/// </example>
778+
public FieldBuilder<TSource, IEnumerable<TReturn>> AddProjectedListField<TProjection, TReturn>(
779+
string name,
780+
Expression<Func<TSource, IEnumerable<TProjection>>> projection,
781+
Func<TProjection, TReturn> transform,
782+
Type? itemGraphType = null,
783+
bool omitQueryArguments = false)
784+
where TReturn : class =>
785+
GraphQlService.AddProjectedListField(this, name, projection, transform, itemGraphType, omitQueryArguments);
786+
787+
public FieldBuilder<TSource, IEnumerable<TReturn>> AddProjectedListField<TProjection, TReturn>(
788+
string name,
789+
Expression<Func<TSource, IEnumerable<TProjection>>> projection,
790+
Func<TProjection, Task<TReturn>> transform,
791+
Type? itemGraphType = null,
792+
bool omitQueryArguments = false)
793+
where TReturn : class =>
794+
GraphQlService.AddProjectedListField(this, name, projection, transform, itemGraphType, omitQueryArguments);
795+
796+
#endregion
797+
798+
#region Simplified API - AddProjectedConnectionField (connection projection from TSource)
799+
800+
/// <summary>
801+
/// Adds a paginated connection field that projects from the source entity and transforms each item.
802+
/// Simplified API - projection is directly from TSource.
803+
/// </summary>
804+
/// <example>
805+
/// AddProjectedConnectionField(
806+
/// name: "childNamesConnection",
807+
/// projection: parent => parent.Children.Select(c => c.Name),
808+
/// transform: name => name.ToUpper())
809+
/// </example>
810+
public ConnectionBuilder<TSource> AddProjectedConnectionField<TProjection, TReturn>(
811+
string name,
812+
Expression<Func<TSource, IEnumerable<TProjection>>> projection,
813+
Func<TProjection, TReturn> transform,
814+
Type? itemGraphType = null,
815+
bool omitQueryArguments = false)
816+
where TReturn : class =>
817+
GraphQlService.AddProjectedConnectionField(this, name, projection, transform, itemGraphType, omitQueryArguments);
818+
819+
public ConnectionBuilder<TSource> AddProjectedConnectionField<TProjection, TReturn>(
820+
string name,
821+
Expression<Func<TSource, IEnumerable<TProjection>>> projection,
822+
Func<TProjection, Task<TReturn>> transform,
823+
Type? itemGraphType = null,
824+
bool omitQueryArguments = false)
825+
where TReturn : class =>
826+
GraphQlService.AddProjectedConnectionField(this, name, projection, transform, itemGraphType, omitQueryArguments);
827+
828+
#endregion
735829
}

0 commit comments

Comments
 (0)