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

  • server.getMiddleware({cors: {}})
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    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 serverWillStart() {
            return {
              schemaDidLoadOrUpdate({ apiSchema, coreSupergraphSdl }) {
                console.log(`The API schema is ${printSchema(apiSchema)}`);
                if (coreSupergraphSdl) {
                  console.log(`The core schema is ${coreSupergraphSdl}`);
                }
              },
            };
          },
        },
      ],
    });
    <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 { ApolloServer, gql } = require('apollo-server');
    const { bootstrap: bootstrapGlobalAgent } = require('global-agent');
    
    // Setup global support for environment variable based proxy configuration.
    bootstrapGlobalAgent();
    
    // The following represents existing configuration, though its
    // important to bootstrap the agent before Apollo Server.
    const server = new ApolloServer({
      typesDefs,
      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
    0
  • const server = new ApolloServer({
      /* ... other necessary configuration ... */
    
      plugins: [
        {
          async serverWillStart() {
            console.log('Server starting!');
          }
        }
      ]
    })
    <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 { 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
  • 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: 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}})
    <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({onHealthCheck})
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • module.exports = {
        Mutation: {
            async login(_, { username, password }) {
                const { errors, valid } = validateLoginInput(username, password);
    
                if (!valid) {
                    throw new UserInputError("Validation error", { errors });
                }
    
                const user = await User.findOne({ username });
    
                
    
                //...
    },
            
            //...
    ,
        },
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">{</span> Mutation<span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token function">login</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> username<span class="token punctuation">,</span> password <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> username<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> password<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 operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></span><span class="token punctuation">;</span> <span class="token function">register</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> registerInput<span class="token operator">:</span> <span class="token punctuation">{</span> username<span class="token punctuation">,</span> email<span class="token punctuation">,</span> password<span class="token punctuation">,</span> confirmPassword <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> registerInput<span class="token operator">:</span> <span class="token punctuation">{</span> username<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> email<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> password<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> confirmPassword<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 operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token operator">...</span><span class="token operator">></span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></code></pre>
    /rimijoker/Social-Media-App GPL-3.0
    0
  • module.exports = {
      
      //...
    ,
      Mutation: {
        
        //...
    ,
        async likePost(_, { postId }, context) {
          
          //...
    if (post) {
            
            //...
    await post.save();
            return post;
          } else throw new UserInputError('Post not found');
        }
      },
      
      //...
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><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">getPosts</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></span><span class="token punctuation">;</span> <span class="token function">getPost</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> postId <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> postId<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 operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></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">createPost</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> body <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> body<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> context<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span>Document<span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token punctuation">,</span> <span class="token builtin">any</span><span class="token punctuation">,</span> <span class="token builtin">any</span><span class="token operator">>></span><span class="token punctuation">;</span> <span class="token function">deletePost</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> postId <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> context<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token operator">...</span><span class="token operator">></span><span class="token punctuation">;</span> <span class="token function">likePost</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> postId <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> context<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token operator">...</span><span class="token operator">></span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> Subscription<span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></code></pre>
    /MLH-Fellowship/0.4.1-Quarantime mit
    0
  • async getData({
        esIndex, esType, fields, filter, sort, offset, size,
      }) {
        if (typeof size !== 'undefined' && offset + size > SCROLL_PAGE_SIZE) {
          throw new UserInputError(`Large graphql query forbidden for offset + size > ${SCROLL_PAGE_SIZE},
          offset = ${offset} and size = ${size},
          please use download endpoint for large data queries instead.`);
        }
        
        //...
    }
    
      
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>method<span class="token punctuation">)</span> <span class="token constant">ES</span><span class="token punctuation">.</span><span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">{</span> esIndex<span class="token punctuation">,</span> esType<span class="token punctuation">,</span> fields<span class="token punctuation">,</span> filter<span class="token punctuation">,</span> sort<span class="token punctuation">,</span> offset<span class="token punctuation">,</span> size<span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> esIndex<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> esType<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> fields<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> filter<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> sort<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> offset<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> size<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 operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></span></code></pre>
    /uc-cdis/guppy Apache-2.0
    0
  • module.exports = new graphql.GraphQLScalarType({
      
      //...
    ,
    
      parseLiteral(ast) {
        if (typeof ast.value !== 'string') {
          throw new UserInputError('Cursor should be a string.');
        }
    
        
    
        //...
    },
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> graphql<span class="token punctuation">.</span>GraphQLScalarType</code></pre>
    /foretold-app/foretold mit
    0
  • module.exports = {
      Mutation: {
        async login(_, { username, password }) {
          const { errors, valid } = validateLoginInput(username, password);
    
          if (!valid) {
            throw new UserInputError('Errors', { errors });
          }
    
          const user = await User.findOne({ username });
    
          
    
          //...
    },
        
        //...
    }
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">{</span> Mutation<span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token function">login</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> username<span class="token punctuation">,</span> password <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> username<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> password<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 operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></span><span class="token punctuation">;</span> <span class="token function">register</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> registerInput<span class="token operator">:</span> <span class="token punctuation">{</span> username<span class="token punctuation">,</span> email<span class="token punctuation">,</span> password<span class="token punctuation">,</span> confirmPassword <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> registerInput<span class="token operator">:</span> <span class="token punctuation">{</span> username<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> email<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> password<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> confirmPassword<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 operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token operator">...</span><span class="token operator">></span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></code></pre>
    /MLH-Fellowship/0.4.1-Quarantime mit
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples