Skip to content

Commit

Permalink
fix(use): rename useGraphQLPlayground to usePlayground
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Jul 31, 2022
1 parent f913b23 commit 5f20761
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ server:
```ts
import {
createHandler,
useGraphQLPlayground,
usePlayground,
} 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";
Expand All @@ -41,7 +41,7 @@ let handler = createHandler(schema, {
hello: "world",
},
});
handler = useGraphQLPlayground(handler);
handler = usePlayground(handler);

serve((req) => {
const { pathname } = new URL(req.url);
Expand Down Expand Up @@ -300,7 +300,7 @@ type jsonObject = {
- `DOMException`
- `AggregateError`

### useGraphQLPlayground
### usePlayground

Use GraphQL Playground as handler.

Expand All @@ -309,7 +309,7 @@ Use GraphQL Playground as handler.
```ts
import {
createHandler,
useGraphQLPlayground,
usePlayground,
} from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
import { buildSchema } from "https://esm.sh/graphql@$VERSION";

Expand All @@ -322,7 +322,7 @@ let handler = createHandler(schema, {
hello: "world",
},
});
handler = useGraphQLPlayground(handler);
handler = usePlayground(handler);
const req = new Request("<ENDPOINT>");
const res = await handler(req);
```
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { default as gqlFetch } from "./fetch.ts";
export { createRequest, resolveRequest } from "./requests.ts";
export { createResponse, resolveResponse } from "./responses.ts";
export { gql } from "./utils.ts";
export { default as useGraphQLPlayground } from "./use/graphql_playground.ts";
export { default as usePlayground } from "./use/playground.ts";
6 changes: 3 additions & 3 deletions use/graphql_playground.ts → use/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { validatePlaygroundRequest } from "../validates.ts";
* ```ts
* import {
* createHandler,
* useGraphQLPlayground,
* usePlayground,
* } from "https://deno.land/x/graphql_http@$VERSION/mod.ts";
* import { buildSchema } from "https://esm.sh/graphql@$VERSION";
*
Expand All @@ -25,12 +25,12 @@ import { validatePlaygroundRequest } from "../validates.ts";
* hello: "world",
* },
* });
* handler = useGraphQLPlayground(handler);
* handler = usePlayground(handler);
* const req = new Request("<ENDPOINT>");
* const res = await handler(req);
* ```
*/
export default function useGraphQLPlayground(
export default function usePlayground(
handler: (req: Request) => Promise<Response> | Response,
/**
* @default `{ endpoint: "/graphql"}`
Expand Down
12 changes: 6 additions & 6 deletions use/graphql_playground_test.ts → use/playground_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import useGraphQLPlayground from "./graphql_playground.ts";
import usePlayground from "./playground.ts";
import createHandler from "../handler.ts";
import { describe, expect, it } from "../dev_deps.ts";
import { buildSchema, contentType, Status } from "../deps.ts";

describe("useGraphQLPlayground", () => {
describe("usePlayground", () => {
it("should render graphql playground when method is GET and accept includes text/html", async () => {
const handler = useGraphQLPlayground(() => new Response());
const handler = usePlayground(() => new Response());
const req = new Request("http://localhost/test.com", {
method: "GET",
headers: {
Expand All @@ -25,7 +25,7 @@ describe("useGraphQLPlayground", () => {

it("should return next response when request is not to playground", async () => {
const nextRes = new Response();
const handler = useGraphQLPlayground(() => nextRes);
const handler = usePlayground(() => nextRes);
const req = new Request("http://localhost/test.com", {
method: "POST",
headers: {
Expand All @@ -38,7 +38,7 @@ describe("useGraphQLPlayground", () => {
it("should return graphql request result when the request is to graphql", async () => {
let handler = createHandler(buildSchema(`type Query { hello: String }`));

handler = useGraphQLPlayground(handler);
handler = usePlayground(handler);
const req = new Request("http://localhost/test.com?query=query{hello}", {
method: "GET",
});
Expand All @@ -56,7 +56,7 @@ describe("useGraphQLPlayground", () => {
it("should return graphql playground result when the request is to graphql playground", async () => {
let handler = createHandler(buildSchema(`type Query { hello: String }`));

handler = useGraphQLPlayground(handler);
handler = usePlayground(handler);
const req = new Request("http://localhost/test.com", {
method: "GET",
headers: {
Expand Down

0 comments on commit 5f20761

Please sign in to comment.