How to use the apollo-server.apolloExpress 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 feats / perfect-graphql-starter / server / index.js View on Github external
import express from 'express';
import bodyParser from 'body-parser';
import { apolloExpress, graphiqlExpress } from 'apollo-server';
import schema from '/domain/schemas';
import connectors from './connectors';
import resolvers from './resolvers';

// Initial fixtures
require('./fixtures').run(connectors.MongoDB.connect());

const PORT = 8080;
const app = express();

app.use('/graphql', bodyParser.json(), apolloExpress({
  schema,
  resolvers,
  context: {},
  formatError(error) {
    console.error(error.stack);
    return error;
  },
}));

app.use(
  '/graphiql',
  graphiqlExpress({
    endpointURL: '/graphql',
  })
);
github jangerhofer / apolloFileUpload / server / main.js View on Github external
};

const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

let graphQLServer = express();

// Configure multer to accept a single file per post
const storage = multer.memoryStorage();
graphQLServer.use(multer({
  storage,
}).single('file'));

graphQLServer.use('/graphql', bodyParser.json(), apolloExpress((req) => ({
  schema,
  rootValue: req,
})
));

graphQLServer.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql',
}));

WebApp.connectHandlers.use(Meteor.bindEnvironment(graphQLServer));
github rricard / movieql / data / server.js View on Github external
initSfdcConnection().then(() => {
  app.use('/graphql', bodyParser.json(), logIncomingGraphQL, apolloExpress({
    schema,
    context: {
      loaders: createLoaders(),
    },
    formatError: (error: Error) => {
      console.error('GraphQL execution error:', error.stack);
      return error.message;
    },
    formatResponse: (data: any) => {
      console.info('✅ Outgoing GraphQL Response');
      console.info('----------------------------');
      console.info(JSON.stringify(data, null, ' '));
      console.info('');
      console.info('');
      return data;
    }
github react-native-training / apollo-graphql-mongodb-react-native / apolloserver / app.js View on Github external
});

const seed = require('./seed');

seed();

const Schema = require('./schema');
const Resolvers = require('./resolvers');
const Connectors = require('./connectors');

const executableSchema = makeExecutableSchema({
  typeDefs: Schema,
  resolvers: Resolvers,
});

app.use('/graphql', bodyParser.json(), apolloExpress({
  schema: executableSchema,
  context: {
    constructor: Connectors,
  },
  rootValue: 'Hello World',
}));

app.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql',
}));

app.listen(PORT, () => console.log(
  `GraphQL Server is now running on http://localhost:${PORT}/graphql`
));
github graphitejs / server / packages / graphite-apollo-express / src / graphql / graphQLServer.js View on Github external
delete Resolvers.Query;
    }

    try {
      this.executableSchema = makeExecutableSchema({
        typeDefs: typeDefs(Types, Query, Mutation),
        resolvers: Resolvers,
        logger: { log: this.customLogger.bind(this) },
      });
    } catch (err) {
      this.logger(err);
    }
    collections.filter(this.hasPropertyInitialize.bind(this))
               .forEach(this.executeInitialize.bind(this));

    const apollo = apolloExpress(this.requestApolloExpress.bind(this));
    this.Graphite.use('/graphql', cors(), bodyParser.json(), apollo);
    this.Graphite.use('/graphiql', bodyParser.json(), graphiqlExpress({
      endpointURL: '/graphql',
    }));

    this.Graphite.listen(GRAPHQL_PORT, this.listenGraphQl.bind(this, GRAPHQL_PORT));
    this.Graphite.getSchema = () => getSchema(`http://localhost:${GRAPHQL_PORT}/graphql`);
    return this.Graphite;
  }