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 { ApolloServer } = require('apollo-server');
    
    const typeDefs = require('./schema');
    const resolvers = require('./resolvers');
    
    const server = new ApolloServer({ typeDefs, resolvers });
    
    server.listen().then(({ url }) => {
      console.log(`πŸš€  Server ready at ${url}`);
    });
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">import</span> ApolloServer</code></pre>
    /wiicamp/graphql-merge-resolvers mit
    1
  • 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}`)
    });
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">class</span> <span class="token class-name">ApolloServer</span> <span class="token keyword">import</span> ApolloServer</code></pre>
    Docs
    1
  • (async () => {
      
      //...
    const server = new ApolloServer({
        schema,
        executor,
        context: ({ req }) => {
          return {
            Authorization: req.headers.authorization || null
          };
        }
      });
    
      server.listen().then(({ url }) => {
        console.log(`πŸš€ Server ready at ${url}`);
      });
    })()
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> server<span class="token operator">:</span> ApolloServer</code></pre>
    /mirumee/gql-federation-gateway bsd-3-clause
    0
  • //...
    const { ApolloServer } = require("apollo-server");
    const { typeDefs } = require("./typeDefs");
    const { resolvers } = require("./resolvers");
    
    const server = new ApolloServer({
      typeDefs,
      resolvers,
      introspection: true,
      playground: true,
    });
    
    server.listen({ port: process.env.PORT || 4000 }).then(({ url }) => {
      console.log(`πŸš€ Server ready at ${url}`);
    });
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">class</span> <span class="token class-name">ApolloServer</span> <span class="token keyword">import</span> ApolloServer</code></pre>
    /konstantinmuenster/graphql-weather-api MIT
    0
  • //...
    // Pass the ApolloGateway to the ApolloServer constructor
    const server = new ApolloServer({
      gateway,
    
      // Disable subscriptions (not currently supported with ApolloGateway)
      subscriptions: false,
    });
    
    server.listen(8082).then(({ url }) => {
      console.log(`πŸš€ Server ready at ${url}`);
    });
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> server<span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    /dgraph-io/graphql-sample-apps Apache-2.0
    0
  • const { ApolloServer, gql } = require('apollo-server');
    const { GraphQLScalarType, Kind } = require('graphql');
    
    const typeDefs = gql`
      scalar Date
    
      type Event {
        id: ID!
        date: Date!
      }
    
      type Query {
        events: [Event!]
      }
    `;
    
    const dateScalar = new GraphQLScalarType({
      // See definition above
    });
    
    const resolvers = {  Date: dateScalar  // ...other resolver definitions...};
    const server = new ApolloServer({
      typeDefs,
      resolvers
    });
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">class</span> <span class="token class-name">ApolloServer</span> <span class="token keyword">import</span> ApolloServer</code></pre>
    Docs
    1
  • 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}`)
    });
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">class</span> <span class="token class-name">ApolloServer</span> <span class="token keyword">import</span> ApolloServer</code></pre>
    Docs
    1
  • const server = new ApolloServer({
      /* ... other necessary configuration ... */
    
      plugins: [
        {
          async requestDidStart(requestContext) {
            // Within this returned object, define functions that respond
            // to request-specific lifecycle events.
            return {
              // The `parsingDidStart` request lifecycle event fires
              // when parsing begins. The event is scoped within an
              // associated `requestDidStart` server lifecycle event.
              async parsingDidStart(requestContext) {
                console.log('Parsing started!')
              },
            }
          }
        }
      ],
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> server<span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    Docs
    0
  • const server = new ApolloServer({
      /* ... other necessary configuration ... */
    
      plugins: [
        {
          async serverWillStart() {
            return {
              async drainServer() {
                await myCustomServer.drain();
              }
            }
          }
        }
      ]
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> server<span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    Docs
    0
  • const server = new ApolloServer({
      /* ... other necessary configuration ... */
    
      plugins: [
        {
          async requestDidStart(initialRequestContext) {
            return {
              async executionDidStart(executionRequestContext) {
                return {
                  willResolveField({source, args, context, info}) {
                    const start = process.hrtime.bigint();
                    return (error, result) => {
                      const end = process.hrtime.bigint();
                      console.log(`Field ${info.parentType.name}.${info.fieldName} took ${end - start}ns`);
                      if (error) {
                        console.log(`It failed with ${error}`);
                      } else {
                        console.log(`It returned ${result}`);
                      }
                    };
                  }
                }
              }
            }
          }
        }
      ]
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> server<span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    Docs
    0
  • server.getMiddleware({cors: {}})
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • server.createHandler({cors: false})
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • server.createHandler({expressGetMiddlewareOptions: {cors: false}})
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • server.createHandler({cors})
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • server.createHandler({expressGetMiddlewareOptions: {cors}})
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • server.createHandler({expressGetMiddlewareOptions: {onHealthCheck}})`
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • //...
    var resolvers = {
      Query: {
        entries: getEntries,
      },
      Mutation: {
        createEntry: createEntry,
      },
    };
    
    const server = new ApolloServer({
      typeDefs,
      resolvers,
    });
    
    
    
    //...
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">var</span> resolvers<span class="token operator">:</span> <span class="token punctuation">{</span> Query<span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token function-variable function">entries</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">any</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> Mutation<span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token function-variable function">createEntry</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">parent<span class="token operator">:</span> any<span class="token punctuation">,</span> args<span class="token operator">:</span> any<span class="token punctuation">,</span> context<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> clientMutationId<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> entry<span class="token operator">:</span> <span class="token punctuation">{</span> id<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> text<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></code></pre>
    /morrys/offline-examples mit
    0
  • //...
    const typeDefs = require('./typeDefs.js');
    
    const app = express();
    
    const server = new ApolloServer({
      typeDefs,
      resolvers,
      context: ({ req, connection }) => ({
        token: req ? req.headers.authorization : connection.context.authorization,
      }),
    });
    
    server.applyMiddleware({ app, path: '/graphql' });
    
    const httpServer = createServer(app);
    
    //...
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">const</span> typeDefs<span class="token operator">:</span> <span class="token builtin">any</span> <span class="token keyword">import</span> typeDefs</code></pre>
    /PacktPublishing/React-Projects mit
    0
  • //...
    const app = express();
    
    // Apollo Server setup
    const server = new ApolloServer({ typeDefs, resolvers });
    
    // Apply the Apollo GraphQL middleware and set the path to /api
    
    //...
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> app<span class="token operator">:</span> Express</code></pre>
    /javascripteverywhere/api MIT
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples