How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • //...
    const app = express();
    
    // Apollo Server setup
    const server = new ApolloServer({ typeDefs, resolvers });
    
    // Apply the Apollo GraphQL middleware and set the path to /api
    
    //...
    
    /javascripteverywhere/api MIT
  • import { ApolloServer } from 'apollo-server-express';
    import { ApolloServerPluginDrainHttpServer } from 'apollo-server-core';
    import express from 'express';
    import http from 'http';
    
    async function startApolloServer(typeDefs, resolvers) {
      const app = express();
      const httpServer = http.createServer(app);
      const server = new ApolloServer({
        typeDefs,
        resolvers,
        plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
      });
      await server.start();
      server.applyMiddleware({ app });
      await new Promise<void>(resolve => httpServer.listen({ port: 4000 }, resolve));
      console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
    }
    Docs
  • const express = require('express');
    const { ApolloServer } = require('apollo-server-express');
    const { ApolloServerPluginDrainHttpServer } = require('apollo-server-core');
    const { typeDefs, resolvers } = require('./schema');
    const http = require('http');
    
    async function startApolloServer() {
      const app = express();
      const httpServer = http.createServer(app);
      const server = new ApolloServer({
        typeDefs,
        resolvers,
        plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
      });
    
      await server.start();
    
      // Mount Apollo middleware here.
      server.applyMiddleware({ app });
      await new Promise<void>(resolve => httpServer.listen({ port: 4000 }, resolve));
      console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
      return { server, app };
    }
    Docs
  • const express = require('express');
    const { ApolloServer } = require('apollo-server-express');
    const { ApolloServerPluginDrainHttpServer } = require('apollo-server-core');
    const { typeDefs, resolvers } = require('./schema');
    
    async function startApolloServer() {
      const app = express();
      const httpServer = http.createServer(app);
      const server = new ApolloServer({
        typeDefs,
        resolvers,
        plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
      });
    
      await server.start();
    
      // Additional middleware can be mounted at this point to run before Apollo.
      app.use('*', jwtCheck, requireAuth, checkScope);
    
      // Mount Apollo middleware here.
      server.applyMiddleware({ app, path: '/specialUrl' });
      await new Promise<void>(resolve => httpServer.listen({ port: 4000 }, resolve));
      console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
      return { server, app };
    }
    Docs
  • const { ApolloServer } = require('apollo-server');
    
    const server = new ApolloServer({
     typeDefs,
     resolvers,
     context: ({ req }) => {
       // Note: This example uses the `req` argument to access headers,
       // but the arguments received by `context` vary by integration.
       // This means they vary for Express, Koa, Lambda, etc.
       //
       // To find out the correct arguments for a specific integration,
       // see https://www.apollographql.com/docs/apollo-server/api/apollo-server/#middleware-specific-context-fields
    
       // Get the user token from the headers.
       const token = req.headers.authorization || '';
    
       // Try to retrieve a user with the token
       const user = getUser(token);
    
       // Add the user to the context
       return { user };
     },
    });
    
    server.listen().then(({ url }) => {
     console.log(`🚀 Server ready at ${url}`)
    });
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples