graphql-result-proxy

0.1.2 • Public • Published

GraphQL Result Proxy

This module provides a Proxy implementation that takes the result of a graphql execution and produces a version that will throw errors when the key that are located at is accessed.

For example:

const { execute } = require('graphql')
const { createResultProxy } = require('graphql-result-proxy')

const exampleFn = async () => {
  const result = await execute(/* args here */)
  // Let's assume this request is of the form
  // query {
  //   getItem {
  //     keyA
  //     keyB
  //   }
  // }
  // And that there is an error localized to getItem.keyB

  const data = createResultProxy(result)

  // This returns the value of keyA
  console.log(data.getItem.keyA)

  // This would throw the error at keyB
  console.log(data.getItem.keyB)

  // This would throw an error that keyC was not in the original graphql request
  console.log(data.getItem.keyC)
}

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-result-proxy

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

117 kB

Total Files

38

Last publish

Collaborators

  • meiamsome