0.0.5 • Published 2 years ago
graphql-workers v0.0.5
graphql-workers
⚡ Features
🤔 Familiar — thin layer ontop of graphql-js
🪢 defer/stream — incremental delivery out of the box
🚀 Usage
npm add graphql-workers \
graphql@16.1.0-experimental-stream-defer.6
at this stage you need a custom tag to support defer/stream, but this is optional
import { makeHandler, createSchemaResponder } from 'graphql-workers';
// your schem as however you have it defined
declare const schema: GraphQLSchema;
export default {
async fetch(req, env, ctx) {
// ~> create a streamable schema
const { reply } = createSchemaResponder(ctx, schema);
// ~> get the paramaters in way you wish
// maybe its a KV read for Relay persisted queries
const { query, variables, operationName } = await req.json();
// ~> then simply reply
return reply(query, variables, operationName);
}
}
// or a module workers convience method
export default makeHandler(schema);
License
MIT © Marais Rossouw