@corejam/base
Version:
A scaffolding for building progressive GraphQL powered jamstack applications
40 lines • 1.76 kB
JavaScript
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());
});
};
import { ApolloServer } from "apollo-server-micro";
import { print } from "graphql";
import { CorejamServer } from "../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 ApolloServer(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})
*
*/
export function createServerClient() {
return {
query: (input) => __awaiter(this, void 0, void 0, function* () {
return (yield corejamServer).executeOperation({
query: print(input.query),
variables: input.variables,
});
}),
};
}
//# sourceMappingURL=ServerClient.js.map