UNPKG

@graphql-mesh/cli

Version:
31 lines (30 loc) 1.09 kB
export function getGraphQLWSOptions(getBuiltMesh) { return { execute: (args) => args.rootValue.execute(args), subscribe: (args) => args.rootValue.subscribe(args), onSubscribe: async (ctx, _id, params) => { const { getEnveloped } = await getBuiltMesh(); const { schema, execute, subscribe, contextFactory, parse, validate } = getEnveloped({ ...ctx, req: ctx.extra.request, socket: ctx.extra.socket, params, }); const args = { schema, operationName: params.operationName, document: parse(params.query), variableValues: params.variables, contextValue: await contextFactory(), rootValue: { execute, subscribe, }, }; const errors = validate(args.schema, args.document); if (errors.length) return errors; return args; }, }; }