ChilliCream / ChilliCream/graphql-platform
Add interfaces for Connections and Edges
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Product
Hot Chocolate
Is your feature request related to a problem?
It would be nice to have a Connection and Edge interfaces to help build highly reusable fragments.
For example:
{
topSellers: persons(first: 5, sortBy: { monthSales: DESC }) { ...Paging }
topItems: products(first: 5, sortBy: { monthNet: DESC }) { ...Paging }
recentSales: orders(first: 5, where: { total: { gt: 1000 } }, sortBy: { date: DESC }) { ...Paging }
}
fragment Paging on Connection {
totalCount
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
... TableEdges
}
}
fragment TableEdges on Edge {
cursor
node {
... TableNodes
}
}
fragment TableNodes on Node {
... TablePerson
... TableOrders
... TableProducts
}
# ...
Admittedly using an Edge interface as a fragment actually increases the size of a query but it allows edges to be specified as a member of Connection...
The solution you'd like
I would like to see a Connection and Edge interface in the schema when using cursor pagination (and maybe offset). It would be good if the type and fields had some basic documentation as well in the schema.
I can do this myself with the following code, but I feel like I shouldn't have to:
[ImplementsInterface<ConnectionType>]
[ExtendObjectType(typeof(Connection))]
public class PageExtensions { }
[ImplementsInterface<EdgeType>]
[ExtendObjectType(typeof(HotChocolate.Types.Pagination.IEdge))]
public class EdgeExtensions { }
public class ConnectionType : InterfaceType
{
protected override void Configure(IInterfaceTypeDescriptor descriptor)
{
descriptor.Name("Connection");
descriptor.Field("pageInfo").Type<PageInfoType>();
descriptor.Field("edges").Type("[Edge!]");
descriptor.Field("nodes").Type("[Node!]");
// only works if you set IncludeTotalCount on all connections; not sure how to fix without modifying HC
descriptor.Field("totalCount").Type("Int");
}
}
public class EdgeType : InterfaceType
{
protected override void Configure(IInterfaceTypeDescriptor descriptor)
{
descriptor.Name("Edge");
descriptor.Field("node").Type<NodeType>();
descriptor.Field("cursor").Type("String!");
}
}
public class ImplementsInterfaceAttribute<T> : ObjectTypeDescriptorAttribute
where T : InterfaceType
{
protected override void OnConfigure(IDescriptorContext context, IObjectTypeDescriptor descriptor, Type type)
=> descriptor.Implements<T>();
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pagination types under HotChocolate.Types.Pagination and compare their generated schema with the supplied ConnectionType and EdgeType example. Define the scope for cursor pagination, including the documented pageInfo, edges, nodes, cursor, and optional totalCount fields; done means reusable Connection and Edge interfaces appear in the schema without application-specific extensions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100