Skip to content

Commit 8f7d01b

Browse files
authored
make EfInterfaceGraphType inherit from AutoRegisteringInterfaceGraphType (#1153)
1 parent fe2351e commit 8f7d01b

6 files changed

Lines changed: 40 additions & 41 deletions

File tree

docs/configuration.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -688,49 +688,45 @@ Map a [table-per-hierarchy (TPH) EF Core pattern](https://docs.microsoft.com/en-
688688

689689
### EF Core Entities
690690

691-
<!-- snippet: InheritedEntity.cs -->
692-
<a id='snippet-InheritedEntity.cs'></a>
691+
<!-- snippet: BaseEntity.cs -->
692+
<a id='snippet-BaseEntity.cs'></a>
693693
```cs
694-
public abstract class InheritedEntity
694+
public abstract class BaseEntity
695695
{
696696
public Guid Id { get; set; } = Guid.NewGuid();
697697
public string? Property { get; set; }
698698
public IList<DerivedChildEntity> ChildrenFromBase { get; set; } = [];
699699
}
700700
```
701-
<sup><a href='/src/Tests/IntegrationTests/Graphs/Inheritance/InheritedEntity.cs#L1-L6' title='Snippet source file'>snippet source</a> | <a href='#snippet-InheritedEntity.cs' title='Start of snippet'>anchor</a></sup>
701+
<sup><a href='/src/Tests/IntegrationTests/Graphs/Inheritance/BaseEntity.cs#L1-L6' title='Snippet source file'>snippet source</a> | <a href='#snippet-BaseEntity.cs' title='Start of snippet'>anchor</a></sup>
702702
<!-- endSnippet -->
703703

704704
<!-- snippet: DerivedEntity.cs -->
705705
<a id='snippet-DerivedEntity.cs'></a>
706706
```cs
707707
public class DerivedEntity :
708-
InheritedEntity;
708+
BaseEntity;
709709
```
710710
<sup><a href='/src/Tests/IntegrationTests/Graphs/Inheritance/DerivedEntity.cs#L1-L3' title='Snippet source file'>snippet source</a> | <a href='#snippet-DerivedEntity.cs' title='Start of snippet'>anchor</a></sup>
711711
<!-- endSnippet -->
712712

713713

714714
### GraphQL types
715715

716-
<!-- snippet: InterfaceGraphType.cs -->
717-
<a id='snippet-InterfaceGraphType.cs'></a>
716+
<!-- snippet: BaseGraphType.cs -->
717+
<a id='snippet-BaseGraphType.cs'></a>
718718
```cs
719-
public class InterfaceGraphType :
720-
EfInterfaceGraphType<IntegrationDbContext, InheritedEntity>
719+
public class BaseGraphType :
720+
EfInterfaceGraphType<IntegrationDbContext, BaseEntity>
721721
{
722-
public InterfaceGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
723-
base(graphQlService)
724-
{
725-
Field(_ => _.Id);
726-
Field(_ => _.Property, nullable: true);
722+
public BaseGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
723+
base(graphQlService) =>
727724
AddNavigationConnectionField<DerivedChildEntity>(
728725
name: "childrenFromInterface",
729-
includeNames: [ "ChildrenFromBase" ]);
730-
}
726+
includeNames: ["ChildrenFromBase"]);
731727
}
732728
```
733-
<sup><a href='/src/Tests/IntegrationTests/Graphs/Inheritance/InterfaceGraphType.cs#L1-L13' title='Snippet source file'>snippet source</a> | <a href='#snippet-InterfaceGraphType.cs' title='Start of snippet'>anchor</a></sup>
729+
<sup><a href='/src/Tests/IntegrationTests/Graphs/Inheritance/BaseGraphType.cs#L1-L9' title='Snippet source file'>snippet source</a> | <a href='#snippet-BaseGraphType.cs' title='Start of snippet'>anchor</a></sup>
734730
<!-- endSnippet -->
735731

736732
<!-- snippet: DerivedGraphType.cs -->
@@ -746,7 +742,7 @@ public class DerivedGraphType :
746742
name: "childrenFromInterface",
747743
_ => _.Source.ChildrenFromBase);
748744
AutoMap();
749-
Interface<InterfaceGraphType>();
745+
Interface<BaseGraphType>();
750746
IsTypeOf = obj => obj is DerivedEntity;
751747
}
752748
}

docs/mdsource/configuration.source.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ Map a [table-per-hierarchy (TPH) EF Core pattern](https://docs.microsoft.com/en-
194194

195195
### EF Core Entities
196196

197-
snippet: InheritedEntity.cs
197+
snippet: BaseEntity.cs
198198

199199
snippet: DerivedEntity.cs
200200

201201

202202
### GraphQL types
203203

204-
snippet: InterfaceGraphType.cs
204+
snippet: BaseGraphType.cs
205205

206206
snippet: DerivedGraphType.cs
207207

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;NU5104;CS1573;CS9107;NU1608;NU1109</NoWarn>
5-
<Version>32.3.1</Version>
5+
<Version>32.4.0-beta.1</Version>
66
<LangVersion>preview</LangVersion>
77
<AssemblyVersion>1.0.0</AssemblyVersion>
88
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>

src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
namespace GraphQL.EntityFramework;
22

3-
public class EfInterfaceGraphType<TDbContext, TSource>(IEfGraphQLService<TDbContext> graphQlService) :
4-
InterfaceGraphType<TSource>
3+
public class EfInterfaceGraphType<TDbContext, TSource>(
4+
IEfGraphQLService<TDbContext> graphQlService,
5+
params Expression<Func<TSource, object?>>[]? excludedProperties) :
6+
AutoRegisteringInterfaceGraphType<TSource>(excludedProperties)
57
where TDbContext : DbContext
68
{
9+
public EfInterfaceGraphType(IEfGraphQLService<TDbContext> graphQlService):this(graphQlService, null)
10+
{
11+
}
12+
713
public IEfGraphQLService<TDbContext> GraphQlService { get; } = graphQlService;
814

915
public ConnectionBuilder<TSource> AddNavigationConnectionField<TReturn>(

src/Tests/IntegrationTests/Graphs/Inheritance/BaseGraphType.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
EfInterfaceGraphType<IntegrationDbContext, BaseEntity>
33
{
44
public BaseGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
5-
base(graphQlService)
6-
{
7-
Field(_ => _.Id);
8-
Field(_ => _.Property, nullable: true);
5+
base(graphQlService) =>
96
AddNavigationConnectionField<DerivedChildEntity>(
107
name: "childrenFromInterface",
11-
includeNames: [ "ChildrenFromBase" ]);
12-
}
8+
includeNames: ["ChildrenFromBase"]);
139
}

src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -461,20 +461,21 @@ type BaseConnection {
461461
"A list of all of the edges returned in the connection."
462462
edges: [BaseEdge]
463463
"A list of all of the objects returned in the connection. This is a convenience field provided for quickly exploring the API; rather than querying for \"{ edges { node } }\" when no edge data is needed, this field can be used instead. Note that when clients like Relay need to fetch the \"cursor\" field on the edge to enable efficient pagination, this shortcut cannot be used, and the full \"{ edges { node } } \" version should be used instead."
464-
items: [Base]
464+
items: [BaseEntity]
465465
}
466466

467467
"An edge in a connection from an object to another object of type `Base`."
468468
type BaseEdge {
469469
"A cursor for use in pagination"
470470
cursor: String!
471471
"The item at the end of the edge"
472-
node: Base
472+
node: BaseEntity
473473
}
474474

475-
interface Base {
475+
interface BaseEntity {
476476
id: ID!
477477
property: String
478+
childrenFromBase: [DerivedChild!]!
478479
childrenFromInterface(
479480
"Only return edges after the specified cursor."
480481
after: String,
@@ -489,6 +490,13 @@ interface Base {
489490
ids: [ID!]): DerivedChildConnection!
490491
}
491492

493+
type DerivedChild {
494+
id: ID!
495+
parentId: ID
496+
property: String
497+
typedParentId: ID
498+
}
499+
492500
"A connection from an object to a list of objects of type `DerivedChild`."
493501
type DerivedChildConnection {
494502
"A count of the total number of objects in this connection, ignoring pagination. This allows a client to fetch the first five objects by passing \"5\" as the argument to `first`, then fetch the total count so it could display \"5 of 83\", for example. In cases where we employ infinite scrolling or don't have an exact count of entries, this field will return `null`."
@@ -509,13 +517,6 @@ type DerivedChildEdge {
509517
node: DerivedChild!
510518
}
511519

512-
type DerivedChild {
513-
id: ID!
514-
parentId: ID
515-
property: String
516-
typedParentId: ID
517-
}
518-
519520
type ManyToManyLeft {
520521
rights(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [ManyToManyRight!]!
521522
id: String!
@@ -567,7 +568,7 @@ type Mutation {
567568
parentEntityMutation(id: ID, ids: [ID!], where: [WhereExpression!]): Parent!
568569
}
569570

570-
type Derived implements Base {
571+
type Derived implements BaseEntity {
571572
childrenFromInterface(
572573
"Only return edges after the specified cursor."
573574
after: String,
@@ -585,7 +586,7 @@ type Derived implements Base {
585586
property: String
586587
}
587588

588-
type DerivedWithNavigation implements Base {
589+
type DerivedWithNavigation implements BaseEntity {
589590
childrenFromInterface(
590591
"Only return edges after the specified cursor."
591592
after: String,

0 commit comments

Comments
 (0)