{"name":"graphql-http","version":"0.0.2","description":"A GraphQL client for executing GraphQL queries over HTTP.","main":"index.js","scripts":{"dev":"babel --watch index.js --out-file index.dist.js"},"repository":{"type":"git","url":"git+https://github.com/petermelias/graphql-http.git"},"keywords":["graphql","http","xhr","graphql-client","axios","fetch"],"author":{"name":"Peter M. Elias"},"license":"MIT","bugs":{"url":"https://github.com/petermelias/graphql-http/issues"},"homepage":"https://github.com/petermelias/graphql-http#readme","dependencies":{"axios":"^0.11.0"},"peerDependencies":{},"devDependencies":{"babel-cli":"^6.6.5","babel-eslint":"^6.0.0","babel-plugin-transform-runtime":"^6.8.0","babel-preset-es2015":"^6.6.0","babel-preset-stage-0":"^6.5.0","babel-runtime":"^6.6.1","eslint":"^2.4.0"},"gitHead":"68021db3ca609cff52ad90854624121ef2cf03ec","_id":"graphql-http@0.0.2","_shasum":"9801f96ed8044e29fca700fc77d772c1eb1fc7b9","_from":".","_npmVersion":"3.9.0","_nodeVersion":"6.1.0","_npmUser":{},"dist":{"shasum":"9801f96ed8044e29fca700fc77d772c1eb1fc7b9","tarball":"http://registry-npm.ywwl.com/graphql-http/download/graphql-http-0.0.2.tgz","integrity":"sha512-dkyHfK5qwJlFIUS3MrY9UIAzeZjrJksCynf88NSakCbkFKn0MvpAnzHFzBvFvfSvf+cD5isHxXIOjRK72bk5Ew==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB6KlHzDrTqfUdKOLMjgqWRIaYDRDAFm4vHjZ+eHDIUlAiAfaBFG3qC93LhpiAJPZcA/l8sNimypIsFaeCKPUeYNQw=="}],"size":3791,"noattachment":false,"key":"/graphql-http/-/graphql-http-0.0.2.tgz"},"maintainers":[{"name":"petermelias","email":"petermelias@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/graphql-http-0.0.2.tgz_1464300747172_0.07148382160812616"},"directories":{},"deprecated":"This package has a new owner and has completely changed as of v1! Please go to https://github.com/enisdenjo/graphql-http for more info.","readme":"<div align=\"center\">\n  <br />\n\n  <h3>graphql-http</h3>\n\n  <h6>Simple, pluggable, zero-dependency, <a href=\"https://graphql.github.io/graphql-over-http\">GraphQL over HTTP spec</a> compliant server, client and audit suite.</h6>\n\n[![Continuous integration](https://github.com/graphql/graphql-http/workflows/Continuous%20integration/badge.svg)](https://github.com/graphql/graphql-http/actions?query=workflow%3A%22Continuous+integration%22) [![graphql-http](https://img.shields.io/npm/v/graphql-http.svg?label=graphql-http&logo=npm)](https://www.npmjs.com/package/graphql-http)\n\n<i>Quickly check for compliance? Visit <b>[graphql-http.com](https://graphql-http.com)</b>!</i>\n\n<i>Want a full-featured server? See the <b>[servers section](#servers)</b>!</i>\n\n<i>Need subscriptions? Try <b>[graphql-ws](https://github.com/enisdenjo/graphql-ws)</b> or <b>[graphql-sse](https://github.com/enisdenjo/graphql-sse)</b> instead!</i>\n\n  <br />\n</div>\n\n## Getting started\n\n#### Install\n\n```shell\nyarn add graphql-http\n```\n\n#### Create a GraphQL schema\n\n```js\nimport { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql';\n\n/**\n * Construct a GraphQL schema and define the necessary resolvers.\n *\n * type Query {\n *   hello: String\n * }\n */\nconst schema = new GraphQLSchema({\n  query: new GraphQLObjectType({\n    name: 'Query',\n    fields: {\n      hello: {\n        type: GraphQLString,\n        resolve: () => 'world',\n      },\n    },\n  }),\n});\n```\n\n#### Start the server\n\n##### With [`http`](https://nodejs.org/api/http.html)\n\n```js\nimport http from 'http';\nimport { createHandler } from 'graphql-http/lib/use/http';\nimport { schema } from './previous-step';\n\n// Create the GraphQL over HTTP Node request handler\nconst handler = createHandler({ schema });\n\n// Create a HTTP server using the listener on `/graphql`\nconst server = http.createServer((req, res) => {\n  if (req.url.startsWith('/graphql')) {\n    handler(req, res);\n  } else {\n    res.writeHead(404).end();\n  }\n});\n\nserver.listen(4000);\nconsole.log('Listening to port 4000');\n```\n\n##### With [`http2`](https://nodejs.org/api/http2.html)\n\n_Browsers might complain about self-signed SSL/TLS certificates. [Help can be found on StackOverflow.](https://stackoverflow.com/questions/7580508/getting-chrome-to-accept-self-signed-localhost-certificate)_\n\n```shell\n$ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n  -keyout localhost-privkey.pem -out localhost-cert.pem\n```\n\n```js\nimport fs from 'fs';\nimport http2 from 'http2';\nimport { createHandler } from 'graphql-http/lib/use/http2';\nimport { schema } from './previous-step';\n\n// Create the GraphQL over HTTP Node request handler\nconst handler = createHandler({ schema });\n\n// Create a HTTP/2 server using the handler on `/graphql`\nconst server = http2.createSecureServer(\n  {\n    key: fs.readFileSync('localhost-privkey.pem'),\n    cert: fs.readFileSync('localhost-cert.pem'),\n  },\n  (req, res) => {\n    if (req.url.startsWith('/graphql')) {\n      handler(req, res);\n    } else {\n      res.writeHead(404).end();\n    }\n  },\n);\n\nserver.listen(4000);\nconsole.log('Listening to port 4000');\n```\n\n##### With [`express`](https://expressjs.com/)\n\n```js\nimport express from 'express'; // yarn add express\nimport { createHandler } from 'graphql-http/lib/use/express';\nimport { schema } from './previous-step';\n\n// Create a express instance serving all methods on `/graphql`\n// where the GraphQL over HTTP express request handler is\nconst app = express();\napp.all('/graphql', createHandler({ schema }));\n\napp.listen({ port: 4000 });\nconsole.log('Listening to port 4000');\n```\n\n##### With [`fastify`](https://www.fastify.io/)\n\n```js\nimport Fastify from 'fastify'; // yarn add fastify\nimport { createHandler } from 'graphql-http/lib/use/fastify';\nimport { schema } from './previous-step';\n\n// Create a fastify instance serving all methods on `/graphql`\n// where the GraphQL over HTTP fastify request handler is\nconst fastify = Fastify();\nfastify.all('/graphql', createHandler({ schema }));\n\nfastify.listen({ port: 4000 });\nconsole.log('Listening to port 4000');\n```\n\n##### With [`Koa`](https://koajs.com/)\n\n```js\nimport Koa from 'koa'; // yarn add koa\nimport mount from 'koa-mount'; // yarn add koa-mount\nimport { createHandler } from 'graphql-http/lib/use/koa';\nimport { schema } from './previous-step';\n\nconst app = new Koa();\napp.use(mount('/graphql', createHandler({ schema })));\n\napp.listen({ port: 4000 });\nconsole.log('Listening to port 4000');\n```\n\n##### With [`uWebSockets.js`](https://github.com/uNetworking/uWebSockets.js)\n\n```js\nimport uWS from 'uWebSockets.js'; // yarn add uWebSockets.js@uNetworking/uWebSockets.js#<version>\nimport { createHandler } from 'graphql-http/lib/use/uWebSockets';\nimport { schema } from './previous-step';\n\nuWS\n  .App()\n  .any('/graphql', createHandler({ schema }))\n  .listen(4000, () => {\n    console.log('Listening to port 4000');\n  });\n```\n\n##### With [`Deno`](https://deno.land/)\n\n```ts\nimport { serve } from 'https://deno.land/std@0.151.0/http/server.ts';\nimport { createHandler } from 'https://esm.sh/graphql-http/lib/use/fetch';\nimport { schema } from './previous-step';\n\n// Create the GraphQL over HTTP native fetch handler\nconst handler = createHandler({ schema });\n\n// Start serving on `/graphql` using the handler\nawait serve(\n  (req: Request) => {\n    const [path, _search] = req.url.split('?');\n    if (path.endsWith('/graphql')) {\n      return handler(req);\n    } else {\n      return new Response(null, { status: 404 });\n    }\n  },\n  {\n    port: 4000, // Listening to port 4000\n  },\n);\n```\n\n##### With [`Bun`](https://bun.sh/)\n\n```js\nimport { createHandler } from 'graphql-http/lib/use/fetch'; // bun install graphql-http\nimport { schema } from './previous-step';\n\n// Create the GraphQL over HTTP native fetch handler\nconst handler = createHandler({ schema });\n\n// Start serving on `/graphql` using the handler\nexport default {\n  port: 4000, // Listening to port 4000\n  fetch(req) {\n    const [path, _search] = req.url.split('?');\n    if (path.endsWith('/graphql')) {\n      return handler(req);\n    } else {\n      return new Response(null, { status: 404 });\n    }\n  },\n};\n```\n\n##### With [`Netlify Functions`](https://docs.netlify.com/functions/overview/)\n\n```js\nimport { createHandler } from 'graphql-http/lib/use/@netlify/functions'; // yarn add @netlify/functions\nimport { schema } from './previous-step';\n\n// Create the GraphQL over HTTP native fetch handler\nexport const handler = createHandler({ schema });\n```\n\n#### Use the client\n\n```js\nimport { createClient } from 'graphql-http';\n\nconst client = createClient({\n  url: 'http://localhost:4000/graphql',\n});\n\n(async () => {\n  let cancel = () => {\n    /* abort the request if it is in-flight */\n  };\n\n  const result = await new Promise((resolve, reject) => {\n    let result;\n    cancel = client.subscribe(\n      {\n        query: '{ hello }',\n      },\n      {\n        next: (data) => (result = data),\n        error: reject,\n        complete: () => resolve(result),\n      },\n    );\n  });\n\n  expect(result).toEqual({ hello: 'world' });\n})();\n```\n\n#### Serve [GraphiQL](https://github.com/graphql/graphiql)\n\nThanks to [`ruru`](https://github.com/graphile/crystal/tree/main/grafast/ruru), serving GraphiQL is as easy as running:\n\n```sh\nnpx ruru -SP -p 4001 -e http://localhost:4000/graphql\n```\n\nOpen [http://localhost:4001](http://localhost:4001) in the browser to use it.\n\n## Recipes\n\n<details id=\"promise\">\n<summary><a href=\"#promise\">🔗</a> Client usage with Promise</summary>\n\n```ts\nimport { ExecutionResult } from 'graphql';\nimport { createClient, RequestParams } from 'graphql-http';\nimport { getSession } from './my-auth';\n\nconst client = createClient({\n  url: 'http://hey.there:4000/graphql',\n  headers: async () => {\n    const session = await getSession();\n    if (session) {\n      return {\n        Authorization: `Bearer ${session.token}`,\n      };\n    }\n  },\n});\n\nfunction execute<Data, Extensions>(\n  params: RequestParams,\n): [request: Promise<ExecutionResult<Data, Extensions>>, cancel: () => void] {\n  let cancel!: () => void;\n  const request = new Promise<ExecutionResult<Data, Extensions>>(\n    (resolve, reject) => {\n      let result: ExecutionResult<Data, Extensions>;\n      cancel = client.subscribe<Data, Extensions>(params, {\n        next: (data) => (result = data),\n        error: reject,\n        complete: () => resolve(result),\n      });\n    },\n  );\n  return [request, cancel];\n}\n\n(async () => {\n  const [request, cancel] = execute({\n    query: '{ hello }',\n  });\n\n  // just an example, not a real function\n  onUserLeavePage(() => {\n    cancel();\n  });\n\n  const result = await request;\n\n  expect(result).toBe({ data: { hello: 'world' } });\n})();\n```\n\n</details>\n\n</details>\n\n<details id=\"observable\">\n<summary><a href=\"#observable\">🔗</a> Client usage with <a href=\"https://github.com/tc39/proposal-observable\">Observable</a></summary>\n\n```js\nimport { Observable } from 'relay-runtime';\n// or\nimport { Observable } from '@apollo/client/core';\n// or\nimport { Observable } from 'rxjs';\n// or\nimport Observable from 'zen-observable';\n// or any other lib which implements Observables as per the ECMAScript proposal: https://github.com/tc39/proposal-observable\nimport { createClient } from 'graphql-http';\nimport { getSession } from './my-auth';\n\nconst client = createClient({\n  url: 'http://graphql.loves:4000/observables',\n  headers: async () => {\n    const session = await getSession();\n    if (session) {\n      return {\n        Authorization: `Bearer ${session.token}`,\n      };\n    }\n  },\n});\n\nconst observable = new Observable((observer) =>\n  client.subscribe({ query: '{ hello }' }, observer),\n);\n\nconst subscription = observable.subscribe({\n  next: (result) => {\n    expect(result).toBe({ data: { hello: 'world' } });\n  },\n});\n\n// unsubscribe will cancel the request if it is pending\nsubscription.unsubscribe();\n```\n\n</details>\n\n<details id=\"relay\">\n<summary><a href=\"#relay\">🔗</a> Client usage with <a href=\"https://relay.dev\">Relay</a></summary>\n\n```ts\nimport { GraphQLError } from 'graphql';\nimport {\n  Network,\n  Observable,\n  RequestParameters,\n  Variables,\n} from 'relay-runtime';\nimport { createClient } from 'graphql-http';\nimport { getSession } from './my-auth';\n\nconst client = createClient({\n  url: 'http://i.love:4000/graphql',\n  headers: async () => {\n    const session = await getSession();\n    if (session) {\n      return {\n        Authorization: `Bearer ${session.token}`,\n      };\n    }\n  },\n});\n\nfunction fetch(operation: RequestParameters, variables: Variables) {\n  return Observable.create((sink) => {\n    if (!operation.text) {\n      return sink.error(new Error('Operation text cannot be empty'));\n    }\n    return client.subscribe(\n      {\n        operationName: operation.name,\n        query: operation.text,\n        variables,\n      },\n      sink,\n    );\n  });\n}\n\nexport const network = Network.create(fetch);\n```\n\n</details>\n\n<details id=\"apollo-client\">\n<summary><a href=\"#apollo-client\">🔗</a> Client usage with <a href=\"https://www.apollographql.com\">Apollo</a></summary>\n\n```ts\nimport {\n  ApolloLink,\n  Operation,\n  FetchResult,\n  Observable,\n} from '@apollo/client/core';\nimport { print, GraphQLError } from 'graphql';\nimport { createClient, ClientOptions, Client } from 'graphql-http';\nimport { getSession } from './my-auth';\n\nclass HTTPLink extends ApolloLink {\n  private client: Client;\n\n  constructor(options: ClientOptions) {\n    super();\n    this.client = createClient(options);\n  }\n\n  public request(operation: Operation): Observable<FetchResult> {\n    return new Observable((sink) => {\n      return this.client.subscribe<FetchResult>(\n        { ...operation, query: print(operation.query) },\n        {\n          next: sink.next.bind(sink),\n          complete: sink.complete.bind(sink),\n          error: sink.error.bind(sink),\n        },\n      );\n    });\n  }\n}\n\nconst link = new HTTPLink({\n  url: 'http://where.is:4000/graphql',\n  headers: async () => {\n    const session = await getSession();\n    if (session) {\n      return {\n        Authorization: `Bearer ${session.token}`,\n      };\n    }\n  },\n});\n```\n\n</details>\n\n<details id=\"request-retries\">\n<summary><a href=\"#request-retries\">🔗</a> Client usage with request retries</summary>\n\n```ts\nimport { createClient, NetworkError } from 'graphql-http';\n\nconst client = createClient({\n  url: 'http://unstable.service:4000/graphql',\n  shouldRetry: async (err: NetworkError, retries: number) => {\n    if (retries > 3) {\n      // max 3 retries and then report service down\n      return false;\n    }\n\n    // try again when service unavailable, could be temporary\n    if (err.response?.status === 503) {\n      // wait one second (you can alternatively time the promise resolution to your preference)\n      await new Promise((resolve) => setTimeout(resolve, 1000));\n      return true;\n    }\n\n    // otherwise report error immediately\n    return false;\n  },\n});\n```\n\n</details>\n\n<details id=\"browser\">\n<summary><a href=\"#browser\">🔗</a> Client usage in browser</summary>\n\n```html\n<!doctype html>\n<html>\n  <head>\n    <meta charset=\"utf-8\" />\n    <title>GraphQL over HTTP</title>\n    <script\n      type=\"text/javascript\"\n      src=\"https://unpkg.com/graphql-http/umd/graphql-http.min.js\"\n    ></script>\n  </head>\n  <body>\n    <script type=\"text/javascript\">\n      const client = graphqlHttp.createClient({\n        url: 'http://umdfor.the:4000/win/graphql',\n      });\n\n      // consider other recipes for usage inspiration\n    </script>\n  </body>\n</html>\n```\n\n</details>\n\n<details id=\"node-client\">\n<summary><a href=\"#node-client\">🔗</a> Client usage in Node</summary>\n\n```js\nconst fetch = require('node-fetch'); // yarn add node-fetch\nconst { AbortController } = require('node-abort-controller'); // (node < v15) yarn add node-abort-controller\nconst { createClient } = require('graphql-http');\n\nconst client = createClient({\n  url: 'http://no.browser:4000/graphql',\n  fetchFn: fetch,\n  abortControllerImpl: AbortController, // node < v15\n});\n\n// consider other recipes for usage inspiration\n```\n\n</details>\n\n<details id=\"deno-client\">\n<summary><a href=\"#deno-client\">🔗</a> Client usage in Deno</summary>\n\n```js\nimport { createClient } from 'https://esm.sh/graphql-http';\n\nconst client = createClient({\n  url: 'http://deno.earth:4000/graphql',\n});\n\n// consider other recipes for usage inspiration\n```\n\n</details>\n\n<details id=\"bun-client\">\n<summary><a href=\"#bun-client\">🔗</a> Client usage in Bun</summary>\n\n```js\nimport { createClient } from 'graphql-http'; // bun install graphql-http\n\nconst client = createClient({\n  url: 'http://bun.bread:4000/graphql',\n});\n\n// consider other recipes for usage inspiration\n```\n\n</details>\n\n<details id=\"migrating-express-graphql\">\n<summary><a href=\"#migrating-express-graphql\">🔗</a> Server handler migration from <a href=\"https://github.com/graphql/express-graphql\">express-graphql</a></summary>\n\n```diff\nimport express from 'express';\nimport { schema } from './my-graphql-schema';\n\n-import { graphqlHTTP } from 'express-graphql';\n+import { createHandler } from 'graphql-http/lib/use/express';\n\nconst app = express();\n\napp.use(\n  '/graphql',\n-  graphqlHTTP({ schema }),\n+  createHandler({ schema }),\n);\n\napp.listen(4000);\n```\n\n</details>\n<details id=\"auth\">\n<summary><a href=\"#auth\">🔗</a> Server handler usage with authentication</summary>\n\nAuthenticate the user within `graphql-http` during GraphQL execution context assembly. This is a approach is less safe compared to early authentication ([see early authentication in Node](#auth-node-early)) because some GraphQL preparations or operations are executed even if the user is not unauthorized.\n\n```js\nimport { createHandler } from 'graphql-http';\nimport {\n  schema,\n  getUserFromCookies,\n  getUserFromAuthorizationHeader,\n} from './my-graphql';\n\nconst handler = createHandler({\n  schema,\n  context: async (req) => {\n    // process token, authenticate user and attach it to your graphql context\n    const userId = await getUserFromCookies(req.headers.cookie);\n    // or\n    const userId = await getUserFromAuthorizationHeader(\n      req.headers.authorization,\n    );\n\n    // respond with 401 if the user was not authenticated\n    if (!userId) {\n      return [null, { status: 401, statusText: 'Unauthorized' }];\n    }\n\n    // otherwise attach the user to the graphql context\n    return { userId };\n  },\n});\n```\n\n</details>\n\n<details id=\"context\">\n<summary><a href=\"#context\">🔗</a> Server handler usage with custom context value</summary>\n\n```js\nimport { createHandler } from 'graphql-http';\nimport { schema, getDynamicContext } from './my-graphql';\n\nconst handler = createHandler({\n  schema,\n  context: async (req, args) => {\n    return getDynamicContext(req, args);\n  },\n  // or static context by supplying the value directly\n});\n```\n\n</details>\n\n<details id=\"custom-exec\">\n<summary><a href=\"#custom-exec\">🔗</a> Server handler usage with custom execution arguments</summary>\n\n```js\nimport { parse } from 'graphql';\nimport { createHandler } from 'graphql-http';\nimport { getSchemaForRequest, myValidationRules } from './my-graphql';\n\nconst handler = createHandler({\n  onSubscribe: async (req, params) => {\n    const schema = await getSchemaForRequest(req);\n\n    const args = {\n      schema,\n      operationName: params.operationName,\n      document: parse(params.query),\n      variableValues: params.variables,\n    };\n\n    return args;\n  },\n});\n```\n\n</details>\n\n<details id=\"auth-node-early\">\n<summary><a href=\"#auth-node-early\">🔗</a> Server handler usage in Node with early authentication (recommended)</summary>\n\nAuthenticate the user early, before reaching `graphql-http`. This is the recommended approach because no GraphQL preparations or operations are executed if the user is not authorized.\n\n```js\nimport { createHandler } from 'graphql-http';\nimport {\n  schema,\n  getUserFromCookies,\n  getUserFromAuthorizationHeader,\n} from './my-graphql';\n\nconst handler = createHandler({\n  schema,\n  context: async (req) => {\n    // user is authenticated early (see below), simply attach it to the graphql context\n    return { userId: req.raw.userId };\n  },\n});\n\nconst server = http.createServer(async (req, res) => {\n  if (!req.url.startsWith('/graphql')) {\n    return res.writeHead(404).end();\n  }\n\n  try {\n    // process token, authenticate user and attach it to the request\n    req.userId = await getUserFromCookies(req.headers.cookie);\n    // or\n    req.userId = await getUserFromAuthorizationHeader(\n      req.headers.authorization,\n    );\n\n    // respond with 401 if the user was not authenticated\n    if (!req.userId) {\n      return res.writeHead(401, 'Unauthorized').end();\n    }\n\n    const [body, init] = await handler({\n      url: req.url,\n      method: req.method,\n      headers: req.headers,\n      body: () =>\n        new Promise((resolve) => {\n          let body = '';\n          req.on('data', (chunk) => (body += chunk));\n          req.on('end', () => resolve(body));\n        }),\n      raw: req,\n    });\n    res.writeHead(init.status, init.statusText, init.headers).end(body);\n  } catch (err) {\n    res.writeHead(500).end(err.message);\n  }\n});\n\nserver.listen(4000);\nconsole.log('Listening to port 4000');\n```\n\n</details>\n\n<details id=\"graphql-upload-http\">\n<summary><a href=\"#graphql-upload-http\">🔗</a> Server handler usage with <a href=\"https://github.com/jaydenseric/graphql-upload\">graphql-upload</a> and <a href=\"https://nodejs.org/api/http.html\">http</a></summary>\n\n```js\nimport http from 'http';\nimport { createHandler } from 'graphql-http/lib/use/http';\nimport processRequest from 'graphql-upload/processRequest.mjs'; // yarn add graphql-upload\nimport { schema } from './my-graphql';\n\nconst handler = createHandler({\n  schema,\n  async parseRequestParams(req) {\n    const params = await processRequest(req.raw, req.context.res);\n    if (Array.isArray(params)) {\n      throw new Error('Batching is not supported');\n    }\n    return {\n      ...params,\n      // variables must be an object as per the GraphQL over HTTP spec\n      variables: Object(params.variables),\n    };\n  },\n});\n\nconst server = http.createServer((req, res) => {\n  if (req.url.startsWith('/graphql')) {\n    handler(req, res);\n  } else {\n    res.writeHead(404).end();\n  }\n});\n\nserver.listen(4000);\nconsole.log('Listening to port 4000');\n```\n\n</details>\n\n<details id=\"graphql-upload-express\">\n<summary><a href=\"#graphql-upload-express\">🔗</a> Server handler usage with <a href=\"https://github.com/jaydenseric/graphql-upload\">graphql-upload</a> and <a href=\"https://expressjs.com/\">express</a></summary>\n\n```js\nimport express from 'express'; // yarn add express\nimport { createHandler } from 'graphql-http/lib/use/express';\nimport processRequest from 'graphql-upload/processRequest.mjs'; // yarn add graphql-upload\nimport { schema } from './my-graphql';\n\nconst app = express();\napp.all(\n  '/graphql',\n  createHandler({\n    schema,\n    async parseRequestParams(req) {\n      const params = await processRequest(req.raw, req.context.res);\n      if (Array.isArray(params)) {\n        throw new Error('Batching is not supported');\n      }\n      return {\n        ...params,\n        // variables must be an object as per the GraphQL over HTTP spec\n        variables: Object(params.variables),\n      };\n    },\n  }),\n);\n\napp.listen({ port: 4000 });\nconsole.log('Listening to port 4000');\n```\n\n</details>\n\n<details id=\"audit-jest\">\n<summary><a href=\"#audit-jest\">🔗</a> Audit for servers usage in <a href=\"https://jestjs.io\">Jest</a> environment</summary>\n\n```js\nimport { fetch } from '@whatwg-node/fetch';\nimport { serverAudits } from 'graphql-http';\n\nfor (const audit of serverAudits({\n  url: 'http://localhost:4000/graphql',\n  fetchFn: fetch,\n})) {\n  test(audit.name, async () => {\n    const result = await audit.fn();\n    if (result.status === 'error') {\n      throw result.reason;\n    }\n    if (result.status === 'warn') {\n      console.warn(result.reason); // or throw if you want full compliance (warnings are not requirements)\n    }\n    // result.status === 'ok'\n  });\n}\n```\n\n</details>\n\n<details id=\"audit-deno\">\n<summary><a href=\"#audit-deno\">🔗</a> Audit for servers usage in <a href=\"https://deno.land\">Deno</a> environment</summary>\n\n```ts\nimport { serverAudits } from 'npm:graphql-http';\n\nfor (const audit of serverAudits({\n  url: 'http://localhost:4000/graphql',\n  fetchFn: fetch,\n})) {\n  Deno.test(audit.name, async () => {\n    const result = await audit.fn();\n    if (result.status === 'error') {\n      throw result.reason;\n    }\n    if (result.status === 'warn') {\n      console.warn(result.reason); // or throw if you want full compliance (warnings are not requirements)\n    }\n    // Avoid leaking resources\n    if ('body' in result && result.body instanceof ReadableStream) {\n      await result.body.cancel();\n    }\n  });\n}\n```\n\nPut the above contents in a file and run it with `deno test --allow-net`.\n\n</details>\n\n## Only [GraphQL over HTTP](https://graphql.github.io/graphql-over-http/)\n\nThis is the official [GraphQL over HTTP spec](https://graphql.github.io/graphql-over-http/) reference implementation and as such follows the specification strictly without any additional features (like playgrounds or GUIs, file uploads, @stream/@defer directives and subscriptions).\n\nHaving said this, graphql-http is mostly aimed for library authors and simple server setups, where the requirements are exact to what the aforementioned spec offers.\n\n## [Servers](/implementations)\n\nIf you want a feature-full server with bleeding edge technologies, you're recommended to use one of the following servers.\n\nTheir compliance with the [GraphQL over HTTP spec](https://graphql.github.io/graphql-over-http) is checked automatically and updated regularly.\n\n<!-- <ServersTable> -->\n<!-- prettier-ignore-start -->\n| Name | Audit |\n|------|-------|\n| [apollo-server](https://www.apollographql.com/docs/apollo-server) | [✅ Compliant](/implementations/apollo-server/README.md) |\n| [deno](https://deno.com/blog/build-a-graphql-server-with-deno) | [✅ Compliant](/implementations/deno/README.md) |\n| [graph-client](https://github.com/graphprotocol/graph-client) | [✅ Compliant](/implementations/graph-client/README.md) |\n| [graphql-helix](https://www.graphql-helix.com) | [✅ Compliant](/implementations/graphql-helix/README.md) |\n| [graphql-yoga](https://www.the-guild.dev/graphql/yoga-server) | [✅ Compliant](/implementations/graphql-yoga/README.md) |\n| [hotchocolate](https://chillicream.com/docs/hotchocolate) | [✅ Compliant](/implementations/hotchocolate/README.md) |\n| [lighthouse](https://lighthouse-php.com) | [✅ Compliant](/implementations/lighthouse/README.md) |\n| [pioneer](https://pioneer.dexclaimation.com) | [✅ Compliant](/implementations/pioneer/README.md) |\n| [postgraphile](https://www.graphile.org/postgraphile) | [✅ Compliant](/implementations/postgraphile/README.md) |\n<!-- prettier-ignore-end -->\n\n<!-- </ServersTable> -->\n\n## [Documentation](docs/)\n\nCheck the [docs folder](docs/) out for [TypeDoc](https://typedoc.org) generated documentation.\n\n## [Audits](implementations/)\n\nInspect audits of other implementations in the [implementations folder](implementations).\nAdding your implementation is very welcome, [see how](CONTRIBUTING.md#adding-implementations)!\n\n## Want to help?\n\nFile a bug, contribute with code, or improve documentation? [Read more in CONTRIBUTING.md](CONTRIBUTING.md).\n\nIf your company benefits from GraphQL and you would like to provide essential financial support for the systems and people that power our community, please also consider membership in the [GraphQL Foundation](https://foundation.graphql.org/join).\n","publish_time":1464300747723,"_cnpm_publish_time":1464300747723,"dist-tags":{"latest":"1.23.1"}}