UNPKG

@commitspark/graphql-api

Version:

GraphQL API to store and manage structured data with Git

65 lines 2.79 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSchema = exports.postGraphQL = void 0; const apollo_config_factory_1 = require("./graphql/apollo-config-factory"); const schema_generator_1 = require("./graphql/schema-generator"); const server_1 = require("@apollo/server"); const postGraphQL = (gitAdapter, ref, request) => __awaiter(void 0, void 0, void 0, function* () { let currentRef = yield gitAdapter.getLatestCommitHash(ref); const context = { branch: ref, gitAdapter: gitAdapter, getCurrentRef() { return currentRef; }, setCurrentRef(refArg) { currentRef = refArg; }, }; const apolloDriverConfig = yield (0, apollo_config_factory_1.createApolloConfig)(context); const apolloServer = new server_1.ApolloServer(Object.assign({}, apolloDriverConfig)); const result = yield apolloServer.executeOperation(request, { contextValue: context, }); yield apolloServer.stop(); return { ref: context.getCurrentRef(), data: result.body.kind === 'single' ? result.body.singleResult.data : undefined, errors: result.body.kind === 'single' ? result.body.singleResult.errors : undefined, }; }); exports.postGraphQL = postGraphQL; const getSchema = (gitAdapter, ref) => __awaiter(void 0, void 0, void 0, function* () { let currentRef = yield gitAdapter.getLatestCommitHash(ref); const context = { branch: ref, gitAdapter: gitAdapter, getCurrentRef() { return currentRef; }, setCurrentRef(refArg) { currentRef = refArg; }, }; const typeDefinitionStrings = (yield (0, schema_generator_1.generateSchema)(context)).typeDefs; if (!Array.isArray(typeDefinitionStrings)) { throw new Error('Expected array of typeDefinition strings.'); } return { ref: context.getCurrentRef(), data: typeDefinitionStrings.join('\n'), }; }); exports.getSchema = getSchema; //# sourceMappingURL=client.js.map