How to use the koa-graphql function in koa-graphql

To help you get started, we’ve selected a few koa-graphql examples, based on popular ways it is used in public projects.

github entria / entria-fullstack / packages / server / src / app.ts View on Github external
// },
    formatError: (error: GraphQLError) => {
      console.log(error.message);
      console.log(error.locations);
      console.log(error.stack);

      return {
        message: error.message,
        locations: error.locations,
        stack: error.stack,
      };
    },
  };
};

const graphqlServer = graphqlHttp(graphqlSettingsPerReq);

// graphql batch query route
router.all('/graphql/batch', bodyParser(), graphqlBatchHttpWrapper(graphqlServer));
router.all('/graphql', graphqlServer);
router.all(
  '/graphiql',
  koaPlayground({
    endpoint: '/graphql',
    subscriptionEndpoint: '/subscriptions',
  }),
);

app.use(logger());
app.use(cors());
app.use(router.routes()).use(router.allowedMethods());
github entria / graphql-dataloader-boilerplate-ts / src / app.ts View on Github external
// },
    formatError: error => {
      console.log(error.message);
      console.log(error.locations);
      console.log(error.stack);

      return {
        message: error.message,
        locations: error.locations,
        stack: error.stack,
      };
    },
  };
};

const graphqlServer = graphqlHttp(graphqlSettingsPerReq);

// graphql batch query route
router.all('/graphql/batch', bodyParser(), graphqlBatchHttpWrapper(graphqlServer));
router.all('/graphql', graphqlServer);
router.all(
  '/playground',
  koaPlayground({
    endpoint: '/graphql',
  }),
);
// router.all(
//   '/graphiql',
//   graphiqlKoa({
//     endpointURL: '/graphql',
//     subscriptionsEndpoint: `ws://localhost:${graphqlPort}/subscriptions`,
//   }),
github Bastiani / bastiani-blog / server / index.ts View on Github external
},
    formatError: (error: GraphQLError): any => {
      console.log(error.message);
      console.log(error.locations);
      console.log(error.stack);

      return {
        message: error.message,
        locations: error.locations,
        stack: error.stack
      };
    }
  };
};

const graphqlServer = convert(graphqlHttp(graphqlSettingsPerReq));

app.prepare().then(() => {
  const server = new Koa();
  const router = new Router();

  router.get('/', async ctx => {
    await handle(ctx.req, ctx.res);
    ctx.respond = false;
  });

  // router.get('/post/:slug', async ctx => {
  //   console.log('========== /post', ctx.params, ctx.query);
  //   // await handle(ctx.req, ctx.res, { query: { slug: ctx.params.slug } });
  //   await app.render(ctx.req, ctx.res, '/post', { slug: ctx.params.slug });
  //   ctx.respond = false;
  // });
github jaburx / pantheon-server / src / app.js View on Github external
// },
    formatError: error => {
      console.log(error.message);
      console.log(error.locations);
      console.log(error.stack);

      return {
        message: error.message,
        locations: error.locations,
        stack: error.stack,
      };
    },
  };
};

const graphqlServer = graphqlHttp(graphqlSettingsPerReq);

// graphql batch query route
router.all('/graphql/batch', bodyParser(), graphqlBatchHttpWrapper(graphqlServer));
router.all('/graphql', graphqlServer);
router.all(
  '/graphiql',
  graphiqlKoa({
    endpointURL: '/graphql',
    subscriptionsEndpoint: `ws://localhost:${graphqlPort}/subscriptions`,
  }),
);
router.all(
  '/playground',
  koaPlayground({
    endpoint: '/graphql',
  }),
github lXSPandora / Workshop-GraphQL / src / app.js View on Github external
},
    formatError: error => {
      console.log(error.message);
      console.log(error.locations);
      console.log(error.stack);

      return {
        message: error.message,
        locations: error.locations,
        stack: error.stack,
      };
    },
  };
};

const graphqlServer = convert(graphqlHttp(graphqlSettingsPerReq));

// graphql batch query route
router.all('/graphql/batch', bodyParser(), graphqlBatchHttpWrapper(graphqlServer));

// graphql standard route
router.all('/graphql', graphqlServer);
app.use(logger());
app.use(cors());
app.use(router.routes()).use(router.allowedMethods());

router.all(
  '/playground',
  koaPlayground({
    endpoint: '/graphql',
  }),
);
github gsasouza / house-automation / packages / server / src / app.ts View on Github external
const router = new Router();

app.context.pubnub = pubNubSetup();


// app.use(morgan('tiny'))
app.use(dataloadersMiddleware)
app.use(authenticatedMiddleware)
router.get('/', ctx => ctx.body = 'Hello World')

router.all('/playground', koaPlayground({
  endpoint: '/graphql',
  subscriptionEndpoint: `ws://localhost:${SERVER_PORT}/subscriptions`,
}))

router.all('/graphql', graphqlHTTP({
  schema,
  graphiql: true
}))

app.use(cors());
app.use(router.routes()).use(router.allowedMethods());

export default app;
github DiscipleD / blog / src / server / server.js View on Github external
import schema from './graphql';
import publish from './publish';

const app = new Koa();

const PORT = Number.parseInt(process.env.PORT || '8080', 10);
const PUBLIC_PATH = path.resolve(__dirname, '../client');
const staticServer = serve(PUBLIC_PATH);

app.use(middleware.serverErrorHandler);
app.use(middleware.pageNotFound);
app.use(middleware.responseTime);
app.use(middleware.logger);

// koa graphql
app.use(mount('/graphql', convert(graphQLHTTP({ schema, pretty: true }))));

// Publish service
app.use(mount('/publish', publish));

if (process.env.NODE_ENV !== 'production') {
	// koa static
	app.use(staticServer);

	const devMiddleware = require('./middleware/webpack-middleware').devMiddleware;
	const hotMiddleware = require('./middleware/webpack-middleware').hotMiddleware;

	app.use(devMiddleware);
	app.use(hotMiddleware);
}

// server render
github entria / graphql-optimizing / version1 / src / app.js View on Github external
instrumentSchema,
  newContext,
} from './instrument';

const app = new Koa();

app.keys = jwtSecret;

const router = new Router();

instrumentSchema(schema);

app.use(logger());
app.use(convert(cors()));
app.use(instrumentMiddleware());
router.all('/graphql', convert(graphqlHTTP(async (req) => {
  console.log('/graphql: ', req._instrumentContext);
  const { user } = await getUser(req.header.authorization);

  return {
    graphiql: process.env.NODE_ENV !== 'production',
    schema,
    context: {
      user,
      instrumentContext: newContext(req),
    },
    formatError: (error) => {
      console.log(error.message);
      console.log(error.locations);
      console.log(error.stack);

      return {
github renanmav / relayable / packages / server / src / app.ts View on Github external
const options: Options = {
    graphiql: process.env.NODE_ENV !== 'production',
    schema,
    context: {
      req,
      res,
      dataloaders,
      user,
      pubSub
    }
  }
  return options
}

const graphqlServer = graphqlHttp(graphqlSettingsPerReq)

router.all('/graphql', bodyParser(), graphqlServer)
if (process.env.NODE_ENV !== 'production') {
  router.all(
    '/graphiql',
    koaPlayground({
      endpoint: '/graphql',
      subscriptionEndpoint: '/subscriptions'
    })
  )
}

app.use(logger())
app.use(cors())
app.use(router.routes()).use(router.allowedMethods())

koa-graphql

Production ready GraphQL Koa middleware.

MIT
Latest version published 10 months ago

Package Health Score

67 / 100
Full package analysis

Popular koa-graphql functions

Similar packages