ContextBasedConnection

public protocol ContextBasedConnection : ConcreteResolvable, OutputResolvable

ContextBasedConnection

Describes an Object used for Cursor-Based Pagination. This API is modeled after standards set by Relay and GraphQL.

It relies on the usage of the arguments: first, after, last and before.

  • first: Number of items that will be fetched at the start of the list
  • after: Cursor of the last element in the page that comes before. Signals that all items in the requested page should be strictly after the element with that cursor. The element with the cursor should be excluded
  • last: Number of items that will be fetched at the end of the list
  • before: Cursor of the first element in the page that comes after. Signals that all items in the requested page should be strictly before the element with that cursor. The element with the cursor should be excluded

Note

This is very similar to ConnectionProtocol.

ContextBasedConnection describes the same functionality of ConnectionProtocolbut attemps to compute certain context information about a page only once.

A type implementing this protocol will first compute a context object that the other methods can use, instead of the raw arguments first, after, last and before. It is intended for scenarios where totalCount, pageInfo and edges all rely on very similar information.

  • Type of Item in the List. Has to conform to OutputResolvable

    Declaration

    Swift

    associatedtype Node where Self.Node == Self.Edge.Node
  • Type of Edges in the List. Edges may contain additional information.

    If no edge type is provided, it will default to the Standard Implementation.

    Declaration

    Swift

    associatedtype Edge : EdgeProtocol = StandardEdge<Self.Node>
  • Context that describes some computations that your other methods need

    Declaration

    Swift

    associatedtype Context
  • Converts the raw page arguments into the required context object.

    Declaration

    Swift

    func context(first: Int?, after: String?, last: Int?, before: String?, eventLoop: EventLoopGroup) -> EventLoopFuture<Context>

    Parameters

    first

    Number of items that will be fetched at the start of the list

    after

    Cursor of the last element in the page that comes before. Signals that all items in the requested page should be strictly after the element with that cursor. The element with the cursor should be excluded

    last

    Number of items that will be fetched at the end of the list

    before

    Cursor of the first element in the page that comes after. Signals that all items in the requested page should be strictly before the element with that cursor. The element with the cursor should be excluded

    eventLoop

    Event Loop Group that can be used to create the futures

    Return Value

    A future with the computed Context object

  • Computes the number of items in the list based on the context.

    Declaration

    Swift

    func totalCount(context: Context, eventLoop: EventLoopGroup) -> EventLoopFuture<Int>

    Parameters

    context

    Precomputed Context

    eventLoop

    Event Loop Group that can be used to create the futures

    Return Value

    A future with the computed count.

  • Computes information about the current page based on the context.. This Information includes the start and end cursor and whether or not there’s adjacent pages.

    Declaration

    Swift

    func pageInfo(context: Context, eventLoop: EventLoopGroup) -> EventLoopFuture<PageInfo>

    Parameters

    context

    Precomputed Context

    eventLoop

    Event Loop Group that can be used to create the futures

    Return Value

    A future with the computed Page Info

  • Computes the edges for the current page

    Declaration

    Swift

    func edges(context: Context, eventLoop: EventLoopGroup) -> EventLoopFuture<[Edge?]?>

    Parameters

    context

    Precomputed Context

    eventLoop

    Event Loop Group that can be used to create the futures

    Return Value

    A future with an array of edges.

  • concreteTypeName Extension method

    Declaration

    Swift

    public static var concreteTypeName: String { get }
  • additionalArguments Extension method

    Warning

    default implementation from GraphZahl. Do not override unless you know exactly what you are doing.

    Declaration

    Swift

    public static var additionalArguments: [String : InputResolvable.Type] { get }
  • resolve(using:) Extension method

    Warning

    default implementation from GraphZahl. Do not override unless you know exactly what you are doing.

    Declaration

    Swift

    public static func resolve(using context: inout Resolution.Context) throws -> GraphQLOutputType
  • Warning

    default implementation from GraphZahl. Do not override unless you know exactly what you are doing.

    Declaration

    Swift

    public func resolve(source: Any, arguments: [String : Map], context: MutableContext, eventLoop: EventLoopGroup) throws -> Output