UNPKG

@graphql-mesh/cli

Version:
29 lines (28 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGraphQLWSOptions = getGraphQLWSOptions; function getGraphQLWSOptions(getBuiltMesh) { return { execute: args => args.rootValue.execute(args), subscribe: args => args.rootValue.subscribe(args), onSubscribe: async (ctx, msg) => { const { getEnveloped } = await getBuiltMesh(); const { schema, execute, subscribe, contextFactory, parse, validate } = getEnveloped(ctx); const args = { schema, operationName: msg.payload.operationName, document: parse(msg.payload.query), variableValues: msg.payload.variables, contextValue: await contextFactory(), rootValue: { execute, subscribe, }, }; const errors = validate(args.schema, args.document); if (errors.length) return errors; return args; }, }; }