import { gql } from "graphql-request"; import { GraphqlService } from "../services"; import { IListCollectionResponse, ICreateCollectionResponse } from '../types'; import { Loader } from "../helpers"; class CollectionService { @Loader('Listing collections !!!') public async listCollections(projectId: string) { const query = gql` query($projectInput: GetProjectInput!){ project(input: $projectInput) { project { collections { archived, changed, changedAt, encodedAt, encoding, encodingAt, id, index, searchableFields { model, field, }, syncAt, syncedAt, syncing, syncingAt, name, } } } } `; const variables = { "projectInput": { "projectId": projectId } }; const response: IListCollectionResponse = await GraphqlService.query(query, variables); return response?.project?.project?.collections || []; } @Loader('Creating collection !!!') public async createCollection(payload: { name: string; projectId: string }) { const mutation = gql` mutation($createCollectionInput: CreateCollectionInput!){ createCollection(input: $createCollectionInput) { collection { archived, changed, changedAt, encodedAt, encoding, encodingAt, id, index, searchableFields { model, field, }, syncAt, syncedAt, syncing, syncingAt, name, } } } `; const variables = { "createCollectionInput": payload, } const response: ICreateCollectionResponse = await GraphqlService.mutation(mutation, variables); return response?.createCollection?.collection; } } export default new CollectionService();