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 listafter
: 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 excludedlast
: Number of items that will be fetched at the end of the listbefore
: 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 ConnectionProtocol
but 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
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
-
concreteTypeName
Extension methodDeclaration
Swift
public static var concreteTypeName: String { get }
-
additionalArguments
Extension methodWarning
default implementation fromGraphZahl
. 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 fromGraphZahl
. Do not override unless you know exactly what you are doing.Declaration
Swift
public static func resolve(using context: inout Resolution.Context) throws -> GraphQLOutputType
-
resolve(source:
Extension methodarguments: context: eventLoop: ) Warning
default implementation fromGraphZahl
. 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