Skip to content

Commit

Permalink
feat: rename gqlHandler to createHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Jul 22, 2022
1 parent 97e3bf0 commit e0167fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ A simple example of creating a GraphQL server and GraphQL client.
server:

```ts
import { gqlHandler } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
import { createHandler } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
import { serve, Status } from "https://deno.land/std@$VERSION/http/mod.ts";
import { buildSchema } from "https://esm.sh/graphql@$VERSION";

const schema = buildSchema(`type Query {
hello: String!
}`);

const handler = gqlHandler(schema, {
const handler = createHandler(schema, {
rootValue: {
hello: "world",
},
Expand Down Expand Up @@ -181,13 +181,13 @@ specification. You can customize this response.
Example of adding a header:

```ts
import { gqlHandler } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
import { createHandler } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
import { buildSchema } from "https://esm.sh/graphql@$VERSION";

const schema = buildSchema(`type Query {
hello: String
}`);
const handler = gqlHandler(schema, {
const handler = createHandler(schema, {
response: (res, ctx) => {
if (ctx.request.method === "GET") {
res.headers.set("Cache-Control", "max-age=604800");
Expand All @@ -211,21 +211,21 @@ or [Websocket](https://developer.mozilla.org/en-US/docs/Web/API/Websockets_API).

## API

### gqlHandler
### createHandler

Create HTTP handler what handle GraphQL over HTTP request.

#### Example

```ts
import { gqlHandler } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
import { createHandler } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
import { buildSchema } from "https://esm.sh/graphql@$VERSION";

const schema = buildSchema(`type Query {
hello: String!
}`);

const handler = gqlHandler(schema, {
const handler = createHandler(schema, {
rootValue: {
hello: "world",
},
Expand Down
4 changes: 2 additions & 2 deletions handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export type Options =
& {
/** Overwrite actual response.
* ```ts
* import { graphqlHttp } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
* import { createHandler } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
* import { buildSchema } from "https://esm.sh/graphql@$VERSION";
*
* const responser = graphqlHttp({
* const handler = createHandler({
* response: (res, ctx) => {
* if (ctx.request.method === "GET") {
* res.headers.set("Cache-Control", "max-age=604800");
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as gqlHandler } from "./handler.ts";
export { default as createHandler } from "./handler.ts";
export { default as gqlFetch } from "./fetch.ts";
export { createRequest, resolveRequest } from "./requests.ts";
export { createResponse, resolveResponse } from "./responses.ts";
Expand Down

0 comments on commit e0167fc

Please sign in to comment.