Skip to content

Releases: Carrotzpc/egg-graphql

use ctx of each request

25 Jun 16:53
Compare
Choose a tag to compare
Pre-release
3.2.0-alpha.3

release 3.2.0-alpha.3

move onPreGraphQL onPrePlayground at the top of the middleware

24 Jun 06:15
Compare
Choose a tag to compare
3.2.0-alpha.2

release 3.2.0-alpha.2

fix issues of onPreGraphQL and onPrePlayground.

21 Jun 07:46
Compare
Choose a tag to compare
  • add miss await for onPreGraphQL and onPrePlayground.

refactor (middleware): use apollo-server-koa directly

10 May 02:09
Compare
Choose a tag to compare
// app/middleware/graphql.js
const { ApolloServer } = require('apollo-server-koa');
const { get } = require('lodash');

module.exports = (_, app) => {
  const options = app.config.graphql;
  const graphQLRouter = options.router || '/graphql';
  let apolloServer;

  return async (ctx, next) => {
    // init apollo server
    if (!apolloServer) {
      const { getApolloServerOptions } = options;
      const apolloServerOptions = Object.assign(
        {
          // log the error stack by default
          formatError: error => {
            const stacktrace = (get(error, 'extensions.exception.stacktrace') || []).join('\n');
            ctx.logger.error('egg-graphql', stacktrace);
            return error;
          },
        },
        options.apolloServerOptions,
        // pass ctx to getApolloServerOptions
        getApolloServerOptions && getApolloServerOptions(ctx),
        // pass schema and context to apollo server
        {
          schema: app.schema,
          context: ctx,
        }
      );
      apolloServer = new ApolloServer(apolloServerOptions);
      apolloServer.applyMiddleware({ app, path: graphQLRouter });
    }

    const { onPreGraphQL, onPrePlayground, playground } = options;
    if (ctx.path === graphQLRouter) {
      if (ctx.request.accepts([ 'json', 'html' ]) === 'html') {
        playground && onPrePlayground && onPrePlayground(ctx);
      } else {
        onPreGraphQL && onPreGraphQL(ctx);
      }
    }

    await next();
  };
};

add ts support

10 May 02:07
Compare
Choose a tag to compare
3.1.0

deps: release 3.1