Interface ConnectionAdapter

All Known Implementing Classes:
CompositeConnectionAdapter, SliceConnectionAdapter, WindowConnectionAdapter

public interface ConnectionAdapter
Contract to adapt any representation of a subset of elements from a larger result set to Connection.
Since:
1.2.0
Author:
Rossen Stoyanchev
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> Object
    createConnection(Object container, List<graphql.relay.Edge<T>> edges, graphql.relay.PageInfo pageInfo)
    Create the Connection.
    cursorAt(Object container, int index)
    Return a cursor for the item at the given index.
    Create a composite ConnectionAdapter that checks which adapter supports a given Object container type and delegates to it.
    <T> Collection<T>
    getContent(Object container)
    Return the contained items as a List.
    boolean
    hasNext(Object container)
    Whether there are more pages after this one.
    boolean
    hasPrevious(Object container)
    Whether there are more pages before this one.
    boolean
    supports(Class<?> containerType)
    Whether the adapter supports the given Object container type.
  • Method Details

    • supports

      boolean supports(Class<?> containerType)
      Whether the adapter supports the given Object container type.
      Parameters:
      containerType - the container type to check for support
    • getContent

      <T> Collection<T> getContent(Object container)
      Return the contained items as a List.
      Type Parameters:
      T - the type of objects in the collection
      Parameters:
      container - the container of elements
    • hasPrevious

      boolean hasPrevious(Object container)
      Whether there are more pages before this one.
      Parameters:
      container - the container of elements
    • hasNext

      boolean hasNext(Object container)
      Whether there are more pages after this one.
      Parameters:
      container - the container of elements
    • cursorAt

      String cursorAt(Object container, int index)
      Return a cursor for the item at the given index.
      Parameters:
      container - the container of elements
      index - the index of an element in the container
    • createConnection

      default <T> Object createConnection(Object container, List<graphql.relay.Edge<T>> edges, graphql.relay.PageInfo pageInfo)
      Create the Connection.

      The relay spec says that a Connection may have additional fields related to the connection, and this method allows adapter implementations to create such an extended Connection.

      By default, DefaultConnection is created.

      Type Parameters:
      T - the type edge node
      Parameters:
      container - the underlying container of elements
      edges - the adapted edges to use
      pageInfo - the page info for the connection
      Since:
      2.0.0
    • from

      static ConnectionAdapter from(List<ConnectionAdapter> adapters)
      Create a composite ConnectionAdapter that checks which adapter supports a given Object container type and delegates to it.
      Parameters:
      adapters - the adapters to delegate to
      Returns:
      the composite adapter instance