cache v0.3

Directives related to caching

StatusRelease
Version0.3

This specification provides a list of directives related to caching.

Some of the definitions directly come from Apollo Server.

1@typePolicy

"""
Defines key fields and embedded fields for an object or interface.
"""
directive @typePolicy(
    """
    A selection set containing fields used to compute the cache key of an object.
    Nested selection sets are not supported. Order is important.

    Key fields can be defined on interfaces. In that case, the key fields apply to all sub-types and sub-types are not allowed to define their own key fields.
    If a type implements multiple interfaces with key fields, the key fields must match across all interfaces with key fields.

    The key fields are automatically added to the operations by the compiler plugin.
    Aliased key fields are not recognized and the compiler adds a non-aliased version of the field if that happens.
    If a type is queried through an interface/union, this may add fragments.

    For an example, this query:

    ```graphql
    query {
        product {
            price
        }
    }
    ```

    is turned into this one after compilation:

    ```graphql
    query {
        product {
            ... on Book {
                isbn
            }
            ... on Movie {
                id
            }
            price
        }
    }
    ```

    """
    keyFields: String! = ""

    """
    A selection set containing fields that should be embedded in their parent Record rather than being stored in their own records.
    Nested selection sets are not supported. Order is unimportant.
    """
    embeddedFields: String! = ""
) on OBJECT | INTERFACE

2@fieldPolicy

"""
Defines key arguments for a given field.
"""
directive @fieldPolicy(
    """
    The name of the field this policy applies to.
    """
    forField: String!

    """
    A list of arguments used to compute the cache key of the object this field points to.
    The list is parsed as a selection set: both spaces and comas are valid separators.
    """
    keyArgs: String! = ""
) repeatable on OBJECT

3@cacheControl

"""
Configures cache settings for a field or type.

- `maxAge`: The maximum amount of time the field's cached value is valid, in seconds.
- `inheritMaxAge`: If true, the field inherits the `maxAge` of its parent field. If set to `true`, `maxAge` must not be provided.
- `scope`: Unused on the client.

When applied to a type, the settings apply to all schema fields that return this type.
Field-level settings override type-level settings.

For example:

```graphql
type Query {
    me: User
    user(id: ID!): User @cacheControl(maxAge: 5)
}

type User @cacheControl(maxAge: 10) {
    id: ID!
    email: String
}
```
`Query.me` is valid for 10 seconds, and `Query.user` for 5 seconds.
"""
directive @cacheControl(
    maxAge: Int
    inheritMaxAge: Boolean
    scope: CacheControlScope
) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | QUERY | MUTATION | SUBSCRIPTION | FRAGMENT_DEFINITION

4@cacheControlField

"""
Configures cache settings for a field.

`@cacheControlField` is the same as `@cacheControl` but can be used on type system extensions for services that do not own the schema like
client services.

For example:

```graphql
# extend the schema to set a max age on User.email.
extend type User @cacheControlField(name: "email", maxAge: 20)
```
`User.email` is valid for 20 seconds.
"""
directive @cacheControlField(
    name: String!
    maxAge: Int
    inheritMaxAge: Boolean
    scope: CacheControlScope
) repeatable on OBJECT | INTERFACE

5CacheControlScope

"""
Possible values for the `@cacheControl` `scope` argument (unused on the client).
"""
enum CacheControlScope {
    PUBLIC
    PRIVATE
}

6@onDelete

"""
Configures the deletion of the child object(s) when the parent object is deleted from the cache.
Must not be applied on scalar (or list of scalar) fields.
- `cascade`: If true, the child object(s) will be deleted from the cache when the parent object is deleted. 

For example:

```graphql
type Author {
  id: ID!
  firstName: String!
  lastName: String!
  book: Book! @onDelete(cascade: true)
}

type Book {
  id: ID!
  title: String!
}
```
Whenever `Author` is deleted from the cache, the associated `Book` is also deleted.
"""
directive @onDelete(
    cascade: Boolean!
) on FIELD_DEFINITION

7@onDeleteField

"""
Configures the deletion of the child object(s) when the parent object is deleted from the cache.
Must not be applied on scalar (or list of scalar) fields.
- `cascade`: If true, the child object(s) will be deleted from the cache when the parent object is deleted. 

`@onDeleteField` is the same as `@onDelete` but can be used on type system extensions for services that do not own the schema like
client services.

For example:

```graphql
# extend the schema to set cascading deletion on Author.book
extend type Author @onDeleteField(name: "book", cascade: true)
```
Whenever `Author` is deleted from the cache, the associated `Book` is also deleted.
"""
directive @onDeleteField(
    name: String!
    cascade: Boolean!
) repeatable on OBJECT | INTERFACE

8@connection

"""
Marks the type as a pagination connection type, as defined by the [Relay Cursor Connections Specification](https://relay.dev/graphql/connections.htm#sec-Connection-Types).
"""
directive @connection on OBJECT

§Index

  1. @cacheControl
  2. @cacheControlField
  3. @connection
  4. @fieldPolicy
  5. @onDelete
  6. @onDeleteField
  7. @typePolicy
  8. CacheControlScope
  1. 1@typePolicy
  2. 2@fieldPolicy
  3. 3@cacheControl
  4. 4@cacheControlField
  5. 5CacheControlScope
  6. 6@onDelete
  7. 7@onDeleteField
  8. 8@connection
  9. §Index