# Relay Modern’s @connection directive URL: https://www.prisma.io/blog/relay-moderns-connection-directive-1ecd8322f5c8 Published: 2017-06-02 Authors: Nikolas Burk Description: Learn how Relay Modern's @connection directive works and how it helps manage pagination and cache behavior in client apps. > Blog posts describe Prisma as it was on the date shown and are not kept current. Before implementing from a post, check the documentation index at https://www.prisma.io/docs/llms.txt and the changelog at https://www.prisma.io/changelog.md. > For an index of every published post, fetch https://www.prisma.io/blog/llms.txt. The @connection directive is new to Relay Modern and unfortunately doesn’t have any official documentation. In this article, we want to give a brief overview on how to use it. If you tried to get started with Relay Modern yourself, chances are you came across the updated [Todo Example](https://github.com/relayjs/relay-examples/tree/master/todo-modern) project on GitHub. If you’ve also studied the [mutations](https://github.com/relayjs/relay-examples/tree/master/todo-modern) in that project, you might have noticed the `@connection` directive that you need to specify when querying *lists* of items. This directive is new to Relay Modern and unfortunately doesn’t have any official documentation yet. In this article, we want to give a brief overview on how to use it. > In Relay, lists are represented through the concept of [connections](https://relay.dev/docs/v10.1.3/graphql-server-specification/#connections). This facilitates the implementation of a [cursor-based pagination](https://relay.dev/docs/v10.1.3/graphql-server-specification/#connections) approach on the client. The `@connection` directive takes two arguments: * `key`: specifies how Relay will refer to this connection in its internal cache * `filter`: represents an array of constraints that are used to filter the items in the connection Let’s take a look at how the directive is used in the Todo example: ### TodoList.js [#todolistjs] ```js export default createFragmentContainer(TodoList, { viewer: graphql` fragment TodoList_viewer on User { todos( first: 2147483647 # max GraphQLInt ) @connection(key: "TodoList_todos") { edges { node { id complete ...Todo_todo } } } id totalCount completedCount ...Todo_viewer } `, }) ``` In `TodoList.js`, the data dependencies for the `TodoList` component are declared in the form of a GraphQL fragment. `todos` refers to a *connection* that's defined in the GraphQL schema. When requesting the items from this list, the `@connection` directive is used alongside the todos field. Relay will use the specified key `TodoList_todos` in its internal cache to refer to that connection. ### AddTodoMutation.js [#addtodomutationjs] ```js function sharedUpdater(store, user, newEdge) { const userProxy = store.get(user.id) const conn = ConnectionHandler.getConnection(userProxy, 'TodoList_todos') ConnectionHandler.insertEdgeAfter(conn, newEdge) } ``` The key is used again in `AddTodoMutation.js`. This time, its purpose is to pull the connection from the internal cache using the `ConnectionHandler` API. The key is passed to the call to `ConnectionHandler.getConnection(...)`. This allows to retrieve the list from the cache and update it manually with the new todo item that was created through the mutation.