Collections

Create, manage and query Collections.

Overview

In Graphlit, content can be grouped into collections, which can contain one or more pieces of content. Content can be added to multiple collections, so it is different than a classic file/folder hierarchy.

For example, you may have a collection of PDFs named "Favorite Research Papers", and a collection of Word documents, PDFs and markdown files named "July uploads", and the same PDF can be a member of both collections.

Collections are named, but the name is not required to be unique across the Graphlit project. Each collection has a unique id field, in GUID format.

Collections are created in the OPENED state, which means that content can be added to or removed from it. See the closeCollection mutation for the ability to close (or lock) the collection, so no content can be added/removed.

Operations

Create Collection

The createCollection mutation enables the creation of a collection by accepting the collection name and it returns essential details, including the ID, name, state, and type of the newly generated collection.

Mutation:

mutation CreateCollection($collection: CollectionInput!) {
  createCollection(collection: $collection) {
    id
    name
    state
    type
  }
}

Variables:

{
  "collection": {
    "name": "Documents"
  }
}

Response:

{
  "type": "COLLECTION",
  "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149",
  "name": "Documents",
  "state": "OPENED"
}
Update Collection

The updateCollection mutation enables the renaming of a collection by accepting the collection name.

Mutation:

mutation UpdateCollection($collection: CollectionUpdateInput!) {
  updateCollection(collection: $collection) {
    id
    name
    state
    type
  }
}

Variables:

{
  "collection": {
    "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149",
    "name": "My Documents"
  }
}

Response:

{
  "type": "COLLECTION",
  "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149",
  "name": "My Documents",
  "state": "OPENED"
}
Delete Collection

The deleteCollection mutation allows the deletion of a collection by utilizing the id parameter, and it returns the ID and state of the deleted collection.

This does not delete the contents contained by the collection, only the collection itself.

Mutation:

mutation DeleteCollection($id: ID!) {
  deleteCollection(id: $id) {
    id
    state
  }
}

Variables:

{
  "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149"
}

Response:

{
  "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149",
  "state": "DELETED"
}
Add Contents to Collections

Using the addContentsToCollections mutation, you can add contents to one or more collections by supplying the collections parameter for the array of entity references for the target collections and the contents parameter, which expects an array of entity references. It returns an array, containing the ID, name, state, type, and the relevant details of the added contents within each collection.

Mutation:

mutation AddContentsToCollections($contents: [EntityReferenceInput!]!, $collections: [EntityReferenceInput!]!) {
  addContentsToCollections(contents: $contents, collections: $collections) {
    id
    name
    state
    type
    contents {
      id
      name
    }
  }
}

Variables:

{
  "contents": [
    {
      "id": "113fd754-1afc-4c12-be4f-abab35385690"
    }
  ],
  "collections": [
    {
      "id": "6ca126e7-7f1e-40ed-8911-1fd89f3f9323"
    }
  ]
}

Response:

[
  {
    "type": "COLLECTION",
    "contents": [
      {
        "id": "113fd754-1afc-4c12-be4f-abab35385690",
        "name": "main.docx"
      }
    ],
    "id": "6ca126e7-7f1e-40ed-8911-1fd89f3f9323",
    "name": "My Documents",
    "state": "OPENED"
  }
]
Remove Contents from Collection

Through the removeContentsFromCollection mutation, you can remove specific contents from a collection by providing the entity reference for the targeted collection and the contents parameter, which expects an array of entity references. Upon execution, it returns the ID, name, state, type, and the pertinent details of the removed contents within the collection.

Mutation:

mutation RemoveContentsFromCollection($contents: [EntityReferenceInput!]!, $collection: EntityReferenceInput!) {
  removeContentsFromCollection(contents: $contents, collection: $collection) {
    id
    name
    state
    type
    contents {
      id
      name
    }
  }
}

Variables:

{
  "contents": [
    {
      "id": "113fd754-1afc-4c12-be4f-abab35385690"
    }
  ],
  "collection": {
    "id": "6ca126e7-7f1e-40ed-8911-1fd89f3f9323"
  }
}

Response:

{
  "type": "COLLECTION",
  "contents": [],
  "id": "6ca126e7-7f1e-40ed-8911-1fd89f3f9323",
  "name": "My Documents",
  "state": "OPENED"
}
Get Collection

The collection query allows you to retrieve specific details of a collection by providing the id parameter, including the ID, name, creation date, state, owner ID, and type associated with the collection.

Query:

query GetCollection($id: ID!) {
  collection(id: $id) {
    id
    name
    creationDate
    state
    owner {
      id
    }
    type
  }
}

Variables:

{
  "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149"
}

Response:

{
  "type": "COLLECTION",
  "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149",
  "name": "My Documents",
  "state": "OPENED",
  "creationDate": "2023-07-02T19:26:52Z",
  "owner": {
    "id": "9422b73d-f8d6-4faf-b7a9-152250c862a4"
  }
}
Query Collections

Query Collections

The collections query allows you to retrieve all collections. It returns a list of collection results, including the ID, name, creation date, state, owner ID, and type for each collection.

Query:

query QueryCollections($filter: CollectionFilter!) {
  collections(filter: $filter) {
    results {
      id
      name
      creationDate
      state
      owner {
        id
      }
      type
    }
  }
}

Variables:

{
  "filter": {
    "offset": 0,
    "limit": 100
  }
}

Response:

{
  "results": [
    {
      "type": "COLLECTION",
      "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149",
      "name": "My Documents",
      "state": "OPENED",
      "creationDate": "2023-07-02T19:26:52Z",
      "owner": {
        "id": "9422b73d-f8d6-4faf-b7a9-152250c862a4"
      }
    }
  ]
}

Query Collections By Name

The collections query allows you to retrieve collections based on a specific filter criteria, via the name parameter. In this example, the name is set to "Documents." It returns a list of collection results containing the ID, name, creation date, state, owner ID, and type for each matching collection.

Query:

query QueryCollections($filter: CollectionFilter!) {
  collections(filter: $filter) {
    results {
      id
      name
      creationDate
      state
      owner {
        id
      }
      type
    }
  }
}

Variables:

{
  "filter": {
    "name": "Documents",
    "offset": 0,
    "limit": 100
  }
}

Response:

{
  "results": [
    {
      "type": "COLLECTION",
      "id": "6d2f8905-b6a1-48bf-b58d-a6441aaa4149",
      "name": "My Documents",
      "state": "OPENED",
      "creationDate": "2023-07-02T19:26:52Z",
      "owner": {
        "id": "9422b73d-f8d6-4faf-b7a9-152250c862a4"
      }
    }
  ]
}

Last updated