New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hydre/graphql-batch-executor

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hydre/graphql-batch-executor

A transform stream executing multiple graphql operations in parallel

  • 3.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-40%
Maintainers
3
Weekly downloads
 
Created
Source

@hydre/graphql-batch-executor

A readable stream executing multiple graphql operations in parallel

This library is made to be used by servers or tools implementer, it can't be used alone.

Install

npm install @hydre/graphql-batch-executor

Usage

Initialize a new Executor per client

import Executor from '@hydre/graphql-batch-executor'
import make_schema from '@hydre/graphql-batch-executor/make_schema'

// i actually wrote a light and efficient version of makeExecutableSchema
// without the shitty code and the 7500 dependencies of graphql-tools
// and using mjs exports of graphql.js
const schema = make_schema({
  document: 'type Query { ping: String! }',
  resolvers: {
    Query: {
      ping: () => 'pong'
    },
    Subscription: {
      ping: {
        resolve: () => 'pong',
        async *subscribe() {
          yield 0
        }
      }
    }
  },
  directives: {
    foo: ({ resolve, // original resolver
            root, // resolver params in the same order
            parameters, // .
            context, // .
            info, // .
            directive_arguments, // parameters for the directive
          }) => {}
  }
})

const executor = new Executor({
  schema, // schema
  context: async () => ({}),
  formatError: x => x // format array of errors
})

The executor generator takes an option object

import stream from 'stream'

stream.pipeline(
    executor.execute({
      document: /* GraphQL */`
          query foo {
            ping
          }

          query bar {
            ping
          }
        `,
      variables: {},
    }),
    async source => {
      for await (const chunk of source) {
        const {
          // query, mutation, subscription
          operation_type,

          // the name
          // note that you can't send queries
          // without names if there are more than one
          operation_name,

          // data result or null
          data,

          // gql errors or []
          errors,
        } = chunk
      }
    },
    () => {
      log('client disconnected')
    },
)

Advanced

see /examples

Keywords

FAQs

Package last updated on 30 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc