UNPKG

@commitspark/graphql-api

Version:

GraphQL API to store and manage structured data with Git

40 lines 1.7 kB
import { createError, ErrorCode } from '../graphql/errors'; export async function getTypeById(gitAdapter, commitHash, id) { const allEntries = await gitAdapter.getEntries(commitHash); const requestedEntry = allEntries.find((entry) => entry.id === id); if (requestedEntry === undefined) { throw createError(`No entry with id "${id}" exists.`, ErrorCode.NOT_FOUND, { argumentName: 'id', argumentValue: id, }); } return requestedEntry.metadata.type; } export async function findById(gitAdapter, commitHash, id) { const allEntries = await gitAdapter.getEntries(commitHash); const requestedEntry = allEntries.find((entry) => entry.id === id); if (requestedEntry === undefined) { throw createError(`No entry with id "${id}" exists.`, ErrorCode.NOT_FOUND, { argumentName: 'id', argumentValue: id, }); } return requestedEntry; } export async function findByType(gitAdapter, commitHash, type) { const allEntries = await gitAdapter.getEntries(commitHash); return allEntries.filter((entry) => entry.metadata.type === type); } export async function findByTypeId(gitAdapter, commitHash, type, id) { const allEntries = await gitAdapter.getEntries(commitHash); const requestedEntry = allEntries.find((entry) => entry.id === id && entry.metadata.type === type); if (requestedEntry === undefined) { throw createError(`No entry of type "${type}" with id "${id}" exists.`, ErrorCode.NOT_FOUND, { typeName: type, argumentName: 'id', argumentValue: id, }); } return requestedEntry; } //# sourceMappingURL=persistence.js.map