UNPKG

@corejam/base

Version:

A scaffolding for building progressive GraphQL powered jamstack applications

44 lines 1.97 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.createServerClient = void 0; const apollo_server_micro_1 = require("apollo-server-micro"); const graphql_1 = require("graphql"); const Server_1 = require("../Server"); /** * This is typed as a promise so we can await in the query() in this instance. * if we dont do that we have an issue because we cant `await` top level in our hydrate * script. */ const corejamServer = new apollo_server_micro_1.ApolloServer(Server_1.CorejamServer()); /** * This function is used for our Stencil Hydrate render process. * We mix this into our coreState client by checking if we are on the server * or on the client (Browser). * * This should only ever be used on the server. * * We inject this query method so we can use the same interface on both the server & * on the client: client.query({query}) * */ function createServerClient() { return { query: (input) => __awaiter(this, void 0, void 0, function* () { return (yield corejamServer).executeOperation({ query: graphql_1.print(input.query), variables: input.variables, }); }), }; } exports.createServerClient = createServerClient; //# sourceMappingURL=ServerClient.js.map