Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -688,49 +688,45 @@ Map a [table-per-hierarchy (TPH) EF Core pattern](https://docs.microsoft.com/en-

### EF Core Entities

<!-- snippet: InheritedEntity.cs -->
<a id='snippet-InheritedEntity.cs'></a>
<!-- snippet: BaseEntity.cs -->
<a id='snippet-BaseEntity.cs'></a>
```cs
public abstract class InheritedEntity
public abstract class BaseEntity
{
public Guid Id { get; set; } = Guid.NewGuid();
public string? Property { get; set; }
public IList<DerivedChildEntity> ChildrenFromBase { get; set; } = [];
}
```
<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>
<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>
<!-- endSnippet -->

<!-- snippet: DerivedEntity.cs -->
<a id='snippet-DerivedEntity.cs'></a>
```cs
public class DerivedEntity :
InheritedEntity;
BaseEntity;
```
<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>
<!-- endSnippet -->


### GraphQL types

<!-- snippet: InterfaceGraphType.cs -->
<a id='snippet-InterfaceGraphType.cs'></a>
<!-- snippet: BaseGraphType.cs -->
<a id='snippet-BaseGraphType.cs'></a>
```cs
public class InterfaceGraphType :
EfInterfaceGraphType<IntegrationDbContext, InheritedEntity>
public class BaseGraphType :
EfInterfaceGraphType<IntegrationDbContext, BaseEntity>
{
public InterfaceGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
base(graphQlService)
{
Field(_ => _.Id);
Field(_ => _.Property, nullable: true);
public BaseGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
base(graphQlService) =>
AddNavigationConnectionField<DerivedChildEntity>(
name: "childrenFromInterface",
includeNames: [ "ChildrenFromBase" ]);
}
includeNames: ["ChildrenFromBase"]);
}
```
<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>
<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>
<!-- endSnippet -->

<!-- snippet: DerivedGraphType.cs -->
Expand All @@ -746,7 +742,7 @@ public class DerivedGraphType :
name: "childrenFromInterface",
_ => _.Source.ChildrenFromBase);
AutoMap();
Interface<InterfaceGraphType>();
Interface<BaseGraphType>();
IsTypeOf = obj => obj is DerivedEntity;
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/mdsource/configuration.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ Map a [table-per-hierarchy (TPH) EF Core pattern](https://docs.microsoft.com/en-

### EF Core Entities

snippet: InheritedEntity.cs
snippet: BaseEntity.cs

snippet: DerivedEntity.cs


### GraphQL types

snippet: InterfaceGraphType.cs
snippet: BaseGraphType.cs

snippet: DerivedGraphType.cs

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;NU5104;CS1573;CS9107;NU1608;NU1109</NoWarn>
<Version>32.3.1</Version>
<Version>32.4.0-beta.1</Version>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>
Expand Down
10 changes: 8 additions & 2 deletions src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
namespace GraphQL.EntityFramework;

public class EfInterfaceGraphType<TDbContext, TSource>(IEfGraphQLService<TDbContext> graphQlService) :
InterfaceGraphType<TSource>
public class EfInterfaceGraphType<TDbContext, TSource>(
IEfGraphQLService<TDbContext> graphQlService,
params Expression<Func<TSource, object?>>[]? excludedProperties) :
AutoRegisteringInterfaceGraphType<TSource>(excludedProperties)
where TDbContext : DbContext
{
public EfInterfaceGraphType(IEfGraphQLService<TDbContext> graphQlService):this(graphQlService, null)
{
}

public IEfGraphQLService<TDbContext> GraphQlService { get; } = graphQlService;

public ConnectionBuilder<TSource> AddNavigationConnectionField<TReturn>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
EfInterfaceGraphType<IntegrationDbContext, BaseEntity>
{
public BaseGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
base(graphQlService)
{
Field(_ => _.Id);
Field(_ => _.Property, nullable: true);
base(graphQlService) =>
AddNavigationConnectionField<DerivedChildEntity>(
name: "childrenFromInterface",
includeNames: [ "ChildrenFromBase" ]);
}
includeNames: ["ChildrenFromBase"]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,21 @@ type BaseConnection {
"A list of all of the edges returned in the connection."
edges: [BaseEdge]
"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."
items: [Base]
items: [BaseEntity]
}

"An edge in a connection from an object to another object of type `Base`."
type BaseEdge {
"A cursor for use in pagination"
cursor: String!
"The item at the end of the edge"
node: Base
node: BaseEntity
}

interface Base {
interface BaseEntity {
id: ID!
property: String
childrenFromBase: [DerivedChild!]!
childrenFromInterface(
"Only return edges after the specified cursor."
after: String,
Expand All @@ -489,6 +490,13 @@ interface Base {
ids: [ID!]): DerivedChildConnection!
}

type DerivedChild {
id: ID!
parentId: ID
property: String
typedParentId: ID
}

"A connection from an object to a list of objects of type `DerivedChild`."
type DerivedChildConnection {
"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`."
Expand All @@ -509,13 +517,6 @@ type DerivedChildEdge {
node: DerivedChild!
}

type DerivedChild {
id: ID!
parentId: ID
property: String
typedParentId: ID
}

type ManyToManyLeft {
rights(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [ManyToManyRight!]!
id: String!
Expand Down Expand Up @@ -567,7 +568,7 @@ type Mutation {
parentEntityMutation(id: ID, ids: [ID!], where: [WhereExpression!]): Parent!
}

type Derived implements Base {
type Derived implements BaseEntity {
childrenFromInterface(
"Only return edges after the specified cursor."
after: String,
Expand All @@ -585,7 +586,7 @@ type Derived implements Base {
property: String
}

type DerivedWithNavigation implements Base {
type DerivedWithNavigation implements BaseEntity {
childrenFromInterface(
"Only return edges after the specified cursor."
after: String,
Expand Down