# Document Formats

Source: https://swapcard.dev/content-api/examples/document-formats


Document Formats are categories organizers assign to Documents (for example <em>Presentation</em>, <em>Abstract</em>, <em>Poster</em>, <em>Handout</em>). They group and order Documents in the Swapcard app, and control how many Documents each exhibitor can add.

A `DocumentFormat` belongs to a Community and is reused across its Events. It is **linked** to each Event where it is used, and that link carries the per-event settings: display order (`index`) and exhibitor document limit (`limit`). These settings are read through `DocumentFormat.withEvent(eventId)`.

Every Document belongs to exactly one Format.

The 7 canonical types are: `EXHIBITOR_DOCUMENTS_AND_LINKS`, `PRESENTATION`, `ABSTRACT`, `POSTER`, `HANDOUT`, `ARTICLE`, `JOB_OFFER`.

#### Object
- [DocumentFormat Object](../graphql-event-api-schema/types/objects/document-format.mdx)
- [DocumentFormatWithEvent Object](../graphql-event-api-schema/types/objects/document-format-with-event.mdx)
- [DocumentFormatGroup Object](../graphql-event-api-schema/types/objects/document-format-group.mdx)

### Fetch Document Formats

Use `Event.documentFormats` to list the Formats linked to an Event, ordered by `index`, or `Community.documentFormats` to list every Format of a Community, linked or not. Both fields are **cursor-paginated** and accept an optional `search` argument (case-insensitive match on the name). `Event.documentFormats` also accepts `filter: { ids }`.

Per-event settings and counts (`limit`, `index`, `documentsCount`) are read through `withEvent(eventId)`, which returns `null` when the Format is not linked to that Event or you cannot access it. `DocumentFormat.documentsCount` counts the Format's Documents across all Events.

#### Query — per event
```graphql
query EventDocumentFormats(
  $eventId: ID!
  $cursor: CursorPaginationInput
  $search: String
) {
  event(id: $eventId) {
    documentFormats(cursor: $cursor, search: $search) {
      pageInfo {
        startCursor
        endCursor
        hasNextPage
        hasPreviousPage
      }
      totalCount
      nodes {
        id
        type
        name
        color
        isDownloadable
        clientId
        translations {
          language
          name
        }
        withEvent(eventId: $eventId) {
          limit
          index
          documentsCount
        }
      }
    }
  }
}
```

#### Variables
```json
{
  "eventId": "RXZlbnRfMQ==",
  "cursor": { "first": 25 },
  "search": "poster"
}
```

#### Query — per community
```graphql
query CommunityDocumentFormats(
  $communityId: ID!
  $cursor: CursorPaginationInput
  $search: String
) {
  communities(filter: { ids: [$communityId] }) {
    nodes {
      id
      documentFormats(cursor: $cursor, search: $search) {
        pageInfo {
          startCursor
          endCursor
          hasNextPage
        }
        totalCount
        nodes {
          id
          type
          name
          clientId
          documentsCount
          linkedEventsCount
          linkedEvents {
            id
          }
        }
      }
    }
  }
}
```

### Fetch the Documents of a Format

#### In an Event

`DocumentFormat.withEvent(eventId).documents` lists the Documents assigned to a Format in an Event. It is cursor-paginated and accepts an optional `search` on the name.

```graphql
query FormatDocuments($eventId: ID!, $cursor: CursorPaginationInput) {
  event(id: $eventId) {
    documentFormats(filter: { ids: ["RG9jdW1lbnRGb3JtYXRfNDI="] }) {
      nodes {
        id
        name
        withEvent(eventId: $eventId) {
          documentsCount
          documents(cursor: $cursor) {
            pageInfo {
              endCursor
              hasNextPage
            }
            nodes {
              id
              translations {
                language
                name
              }
              exhibitors {
                id
                name
              }
              plannings {
                id
                title
              }
            }
          }
        }
      }
    }
  }
}
```

`Document.exhibitors` and `Document.plannings` return the Exhibitors and Sessions a Document is attached to. Reached through an Event, as here, they only return those of that Event.

#### For an exhibitor or a session

`documentFormats` on `ExhibitorWithEvent`, `PlanningWithEvent`, `Exhibitor` and `Planning` returns their Documents grouped by Format, as a list of `DocumentFormatGroup`. Through `withEvent(eventId)`, the groups follow the Event's Format order. Pass `id` to return a single Format.

On an exhibitor in an Event, `canExhibitorManage` is `false` when the exhibitor's resolved limit for the Format is `0`: the exhibitor can no longer add, edit or delete Documents in it from the Swapcard app (see [Exhibitor document limits](#exhibitor-document-limits)). It stays `true` when a cap is reached; compare `exhibitorLimit.used` with `exhibitorLimit.limit` to know if the exhibitor can still add Documents. It is `null` outside an exhibitor in an Event.

```graphql
query ExhibitorDocumentsByFormat($communityId: ID!, $exhibitorId: ID!, $eventId: ID!) {
  exhibitorsV2(communityId: $communityId, filter: { ids: [$exhibitorId] }) {
    nodes {
      id
      withEvent(eventId: $eventId) {
        documentFormats {
          format {
            id
            type
            name
          }
          canExhibitorManage
          documentsConnection(cursor: { first: 20 }) {
            totalCount
            nodes {
              id
              translations {
                language
                name
              }
            }
          }
        }
      }
    }
  }
}
```

### Assign a Document to a Format

Pass `documentFormatId` to [`createDocument`](../graphql-event-api-schema/operations/mutations/create-document.mdx) or [`updateDocument`](../graphql-event-api-schema/operations/mutations/update-document.mdx). The Format must belong to the Document's Community and be linked to the Event(s) the Document belongs to. Otherwise, the mutation returns a `BAD_INPUT` error on `documentFormatId`, or a `NOT_FOUND` error when the Format does not exist. When `documentFormatId` is omitted on creation, the Document goes to the Community's default *Presentation* Format. See the [Documents examples page](graphql-event-api-examples-documents.md).

### Create, update, link and unlink in a single call

The [`importEventDocumentFormats`](../graphql-event-api-schema/operations/mutations/import-event-document-formats.mdx) mutation is the single entry point for all state changes on a Format against an Event: create a Format and link it, update an existing Format, apply per-event overrides, link to another event, unlink. It accepts a batch of inputs and returns a result per input with an `inputId` correlation.

#### Arguments
- `eventId` — The Id of the Event the Formats operate against.
- `formats` — A list of `ImportDocumentFormatInput`. Each entry identifies a target Format (via `id`, `clientId`, or neither for pure create) and declares what to do.
- `validateOnly` — When `true`, runs the full validation pipeline without persisting (dry-run).

Each `ImportDocumentFormatInput` entry is routed as follows:

| Input shape                                                 | Resulting behavior                                                                 |
|-------------------------------------------------------------|------------------------------------------------------------------------------------|
| `{ create: {...} }`                                         | Create Format in the community and auto-link to `eventId`                          |
| `{ clientId: "FMT_X", create: {...} }`                      | Same, with `clientId` persisted on the new Format. Fails with `CLIENT_ID_ALREADY_IN_USE` if a Format already uses this `clientId` |
| `{ clientId: "FMT_X", update: {...} }`                      | Update the Format with this `clientId`. Fails if none exists                       |
| `{ clientId: "FMT_X", create: {...}, update: {...} }`       | Upsert: update the Format with this `clientId`, or create it with `create` if none exists |
| `{ id: X, update: {...} }`                                  | Update the Format's fields                                                         |
| `{ id: X }`                                                 | Idempotent link: if the Format is not yet linked to the event, link it; else no-op |
| `{ id: X, eventLink: { limit, index } }`                    | Set the per-event settings (links the Format first if needed)                      |
| `{ id: X, unlinkFromEvent: true }`                          | Unlink the Format from the event (the Format stays in the community)               |

`eventLink.limit` is the event-level limit of Documents each exhibitor can add in this Format from the Swapcard app: `null` means unlimited, `0` closes the Format to exhibitors, `N` is a cap. When omitted, an existing link keeps its value and a new link gets the type's default: unlimited for `EXHIBITOR_DOCUMENTS_AND_LINKS`, `0` for every other type. See [Exhibitor document limits](#exhibitor-document-limits).

Whatever the input shape, a Format that is not yet linked to `eventId` gets linked to it, unless `unlinkFromEvent` is set.

Errors are reported per input on the result's `errors[]` field, with the `inputId` of the failing entry. Each input is saved on its own, so one failing input does not prevent the others from being saved.

#### Mutation
```graphql
mutation ImportEventDocumentFormats(
  $eventId: ID!
  $formats: [ImportDocumentFormatInput!]!
  $validateOnly: Boolean
) {
  importEventDocumentFormats(
    eventId: $eventId
    formats: $formats
    validateOnly: $validateOnly
  ) {
    results {
      inputId
      documentFormat {
        id
        type
        name
        color
        isDownloadable
        clientId
        translations {
          language
          name
        }
        withEvent(eventId: $eventId) {
          limit
          index
          documentsCount
        }
      }
    }
    errors {
      inputId
      message
      errorCode
      path
    }
    documentFormatCreated
    documentFormatUpdated
  }
}
```

#### Example — create a Format with translations and per-event overrides
```json
{
  "eventId": "RXZlbnRfMQ==",
  "formats": [
    {
      "inputId": "poster-1",
      "clientId": "FMT_POSTER",
      "create": {
        "type": "POSTER",
        "name": "Poster",
        "color": "3366FF",
        "isDownloadable": true,
        "translations": [
          { "language": "en_US", "name": "Poster" },
          { "language": "fr_FR", "name": "Affiche" }
        ]
      },
      "eventLink": { "limit": 10, "index": 2 }
    }
  ]
}
```

#### Example — upsert by clientId (idempotent retry)
Pass both `create` and `update`: the Format with `clientId = "FMT_ABSTRACT"` is updated if it exists, created otherwise. Sending the same input again is safe.
```json
{
  "eventId": "RXZlbnRfMQ==",
  "formats": [
    {
      "inputId": "upsert-abstract",
      "clientId": "FMT_ABSTRACT",
      "create": {
        "type": "ABSTRACT",
        "name": "Extended Abstract",
        "isDownloadable": true
      },
      "update": {
        "name": "Extended Abstract",
        "isDownloadable": true
      }
    }
  ]
}
```

#### Example — link an existing Format to another event
Call the mutation with the target `eventId` and only the `id`:
```json
{
  "eventId": "RXZlbnRfOTk5",
  "formats": [
    { "inputId": "link-only", "id": "RG9jdW1lbnRGb3JtYXRfNDI=" }
  ]
}
```

#### Example — update per-event overrides
```json
{
  "eventId": "RXZlbnRfMQ==",
  "formats": [
    {
      "inputId": "override-limit",
      "id": "RG9jdW1lbnRGb3JtYXRfNDI=",
      "eventLink": { "limit": 5, "index": 9 }
    }
  ]
}
```

#### Example — bulk reorder (3 Formats, update per-event index only)
Each entry only touches `eventLink.index`; the Format fields and the `limit` override stay untouched.
```json
{
  "eventId": "RXZlbnRfMQ==",
  "formats": [
    { "inputId": "reorder-1", "id": "RG9jdW1lbnRGb3JtYXRfNDI=", "eventLink": { "index": 0 } },
    { "inputId": "reorder-2", "id": "RG9jdW1lbnRGb3JtYXRfNDM=", "eventLink": { "index": 1 } },
    { "inputId": "reorder-3", "id": "RG9jdW1lbnRGb3JtYXRfNDQ=", "eventLink": { "index": 2 } }
  ]
}
```

#### Example — unlink from an event
```json
{
  "eventId": "RXZlbnRfMQ==",
  "formats": [
    {
      "inputId": "unlink",
      "id": "RG9jdW1lbnRGb3JtYXRfNDI=",
      "unlinkFromEvent": true
    }
  ]
}
```

Unlink is **blocked** if the event has Documents still assigned to the Format — remove or reassign those Documents first. The error is returned as `BLOCKED_HAS_DOCUMENTS` on the matching `errors[]` entry.

### Delete a Format

Use [`deleteDocumentFormat`](../graphql-event-api-schema/operations/mutations/delete-document-format.mdx) to remove a Format at the community level or unlink it from one specific event. The mutation has 4 branches surfaced through the `result` field:

| Branch                      | When                                                                                   |
|-----------------------------|----------------------------------------------------------------------------------------|
| `BLOCKED_HAS_DOCUMENTS`     | Documents are still assigned to this Format — remove them first                        |
| `DELETED_FROM_COMMUNITY`    | The Format was linked to at most one event, or `mode: HARD_DELETE` was passed          |
| `UNLINKED_FROM_EVENT`       | Multi-event Format, `mode: UNLINK_FROM_EVENT` + `eventId` → only that junction removed |
| `NEEDS_USER_CHOICE`         | Multi-event Format, no `mode` provided — `remainingEventIds` lists the linked events   |

When `result = NEEDS_USER_CHOICE`, re-call the mutation with the user's explicit choice: either `mode: UNLINK_FROM_EVENT` + the target `eventId`, or `mode: HARD_DELETE` to drop the Format community-wide.

#### Mutation
```graphql
mutation DeleteDocumentFormat($input: DeleteDocumentFormatInput!) {
  deleteDocumentFormat(input: $input) {
    result
    remainingEventIds
    errors {
      message
    }
  }
}
```

#### Variables — unlink from one event
```json
{
  "input": {
    "documentFormatId": "RG9jdW1lbnRGb3JtYXRfNDI=",
    "eventId": "RXZlbnRfMQ==",
    "mode": "UNLINK_FROM_EVENT"
  }
}
```

#### Variables — hard delete community-wide
```json
{
  "input": {
    "documentFormatId": "RG9jdW1lbnRGb3JtYXRfNDI=",
    "mode": "HARD_DELETE"
  }
}
```

### Exhibitor document limits

The number of Documents an exhibitor can add **in the Swapcard app** is set per Format and per Event. For a given exhibitor, the limit is resolved in cascade, the first level set wins:

1. **Exhibitor** override: `ExhibitorWithEvent.documentFormatLimits`.
2. **Exhibitor group** override: `EventGroup.documentFormatLimits`. When the exhibitor is in several groups, the most permissive limit applies.
3. **Event** limit: `DocumentFormat.withEvent(eventId).limit`, set through `importEventDocumentFormats` (`eventLink.limit`).

At every level, `null` means unlimited, `0` means the exhibitor can no longer add, edit or delete Documents in this Format, and `N` is a cap. These limits only apply to exhibitors in the Swapcard app: Documents you manage through the Content API are not restricted.

#### Read the limits

`exhibitorLimit(exhibitorId)` returns the resolved `limit` for one exhibitor and the number of Documents it already has in the Format (`used`).

```graphql
query ExhibitorDocumentLimits($communityId: ID!, $exhibitorId: ID!, $eventId: ID!) {
  event(id: $eventId) {
    documentFormats {
      nodes {
        id
        name
        withEvent(eventId: $eventId) {
          limit
          exhibitorLimit(exhibitorId: $exhibitorId) {
            limit
            used
          }
        }
      }
    }
  }
  exhibitorsV2(communityId: $communityId, filter: { ids: [$exhibitorId] }) {
    nodes {
      withEvent(eventId: $eventId) {
        group {
          id
          documentFormatLimits {
            documentFormat {
              id
            }
            limit
          }
        }
        documentFormatLimits {
          documentFormat {
            id
          }
          limit
        }
      }
    }
  }
}
```

Group and exhibitor overrides are sparse: only the Formats with an explicit override are listed. A Format that is not listed inherits from the next level.

#### Set an exhibitor override

Use `documentFormatLimits` in the `withEvent` data of [`updateExhibitor`](../graphql-event-api-schema/operations/mutations/update-exhibitor.mdx). Each entry sets the override for one Format. Formats left out are not changed, and `clear: true` removes the override so the exhibitor inherits from its group or the Event again.

```graphql
mutation UpdateExhibitorDocumentLimits($input: UpdateExhibitorInput!) {
  updateExhibitor(input: $input) {
    exhibitor {
      id
    }
    errors {
      code
      message
    }
  }
}
```

```json
{
  "input": {
    "exhibitorId": "RXhoaWJpdG9yXzEyMw==",
    "withEvent": [
      {
        "eventId": "RXZlbnRfMQ==",
        "data": {
          "documentFormatLimits": [
            { "documentFormatId": "RG9jdW1lbnRGb3JtYXRfNDI=", "limit": 5 },
            { "documentFormatId": "RG9jdW1lbnRGb3JtYXRfNDM=", "limit": 0 },
            { "documentFormatId": "RG9jdW1lbnRGb3JtYXRfNDQ=", "clear": true }
          ]
        }
      }
    ]
  }
}
```

The legacy `documentLimit` field on `UpdateExhibitorInput` and `ExhibitorWithEventDataInput` is deprecated and no longer enforced.
