UNPKG

@graphql-mesh/cli

Version:
26 lines (25 loc) 953 B
export 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; }, }; }