How to use the apollo-server.apolloServer function in apollo-server

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

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github venusdev85 / Vue-Express-Mongo / server / routes / graphql.js View on Github external
module.exports = function(app, db) {

	// Register graphql server
	app.use("/graphql", auth.isAuthenticatedOrApiKey, ApolloServer( (req) => {
		const query = req.query.query || req.body.query;
		if (query && query.length > 2000) {
			// None of our app's queries are this long
			// Probably indicates someone trying to send an overly expensive query
			throw new Error("Query too large.");
		}		

		return {
			graphiql: config.isDevMode(),
			pretty: config.isDevMode(),
			printErrors: config.isDevMode(),
			schema: Schema,
			resolvers: Resolvers,
			logger: { log: (e) => console.error(e.stack) },
			context: {
				user: req.user,
github apollographql / meteor-integration / main-server.js View on Github external
export const createApolloServer = (givenOptions, givenConfig) => {
  const config = _.extend(defaultConfig, givenConfig);

  const graphQLServer = express();

  graphQLServer.use(config.path, apolloServer(async (req) => {
    let options,
        user = null;

    if (_.isFunction(givenOptions))
      options = givenOptions(req);
    else
      options = givenOptions;

    options = Object.assign({}, options)

    // Get the token from the header
    if (req.headers.authorization) {
      const token = req.headers.authorization;
      check(token, String);
      const hashedToken = Accounts._hashLoginToken(token);
github gucheen / fetchql / test / server.js View on Github external
import express from 'express';
import { apolloServer } from 'apollo-server';
import Schema from './schema';
import Mocks from './mocks';

const GRAPHQL_PORT = 4321;

const graphQLServer = express();
graphQLServer.use('/graphql', apolloServer((req) => {
  let headerCheck = req.headers['test-header'] === 'test-header';

  return {
    graphiql: true,
    pretty: true,
    schema: Schema,
    mocks: Mocks(headerCheck)
  };
}));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
  `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql`
));
github ramsaylanier / WordExpress / server.js View on Github external
let app = express();

graphQLServer.use('/', apolloServer({
  graphiql: true,
  pretty: true,
  schema: Definitions,
  resolvers: Resolvers
}));

graphQLServer.listen(GRAPHQL_PORT, () => console.log(
  `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
));

app.use(require('prerender-node').set('prerenderToken', privateSettings.prerenderToken ));
app.use(express.static('./dist'));
app.use('/graphql', apolloServer({
  graphiql: true,
  pretty: true,
  schema: Definitions,
  resolvers: Resolvers
}));
app.get('*', function response(req, res, next) {
  res.sendFile(path.join(__dirname, '/index.html'));
});

app.listen(APP_PORT, () => {
  console.log(`App is now running on http://localhost:${APP_PORT}`);
});
github sammkj / meteor-1.3-todo / imports / server / configs / graphql.js View on Github external
export default function ({ schema, resolvers }) {
  const graphQLServer = express();
  const GRAPHQL_PORT = 4000;

  graphQLServer.use('/graphql', apolloServer({
    graphiql: true,
    pretty: true,
    schema,
    resolvers,
  }));

  graphQLServer.listen(GRAPHQL_PORT, () => console.log(
    `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
  ));

  WebApp.rawConnectHandlers.use(proxyMiddleware(`http://localhost:${GRAPHQL_PORT}/graphql`));
}
github Raathigesh / atmo / src / server / endpoints / graphql.js View on Github external
function registerGraphqlEndpoints(app, endpoints) {
  for (var i = 0; i < endpoints.length; i++) {
    var endpoint = endpoints[i];
    app.use(endpoint.url, apollo.apolloServer({
      graphiql: true,
      pretty: true,
      schema: endpoint.schema,
      mocks: mocks
    }));
  }
}
github kamilkisiela / angular2-graphql-rest / src / server / api / graphql / index.js View on Github external
export default function(app) {
  app.use('/graphql', apolloServer((req) => ({
    graphiql: true,
    pretty: true,
    context: {
      Profiles: new Profiles
    },
    schema,
    resolvers
  })));
}