Skip to content

Latest commit

 

History

History
89 lines (55 loc) · 2.19 KB

use_fetch.md

File metadata and controls

89 lines (55 loc) · 2.19 KB

graphql-http / use/fetch

Module: use/fetch

Table of contents

Interfaces

Type Aliases

Functions

Server/fetch

HandlerOptions

Ƭ HandlerOptions<Context>: HandlerOptions<Request, FetchAPI, Context>

Handler options when using the fetch adapter.

Type parameters

Name Type
Context extends OperationContext = undefined

createHandler

createHandler<Context>(options, reqCtx?): (req: Request) => Promise<Response>

Create a GraphQL over HTTP spec compliant request handler for a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.

You can use @whatwg-node/server to create a server adapter and isomorphically use it in any environment. See an example:

import http from 'http';
import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
import { createHandler } from 'graphql-http/lib/use/fetch';
import { schema } from './my-graphql-schema';

// Use this adapter in _any_ environment.
const adapter = createServerAdapter({
  handleRequest: createHandler({ schema }),
});

const server = http.createServer(adapter);

server.listen(4000);
console.log('Listening to port 4000');

Type parameters

Name Type
Context extends OperationContext = undefined

Parameters

Name Type Description
options HandlerOptions<Context> -
reqCtx Partial<FetchAPI> Custom fetch API engine, will use from global scope if left undefined.

Returns

fn

▸ (req): Promise<Response>

Parameters
Name Type
req Request
Returns

Promise<Response>