-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for graphql playground and areadme
- Loading branch information
1 parent
c475a6e
commit 790d275
Showing
6 changed files
with
71 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# gql/graphiql | ||
|
||
[![][docs-badge]][docs] | ||
|
||
Tweaked version of | ||
[graphql-playground-html](https://github.com/graphql/graphql-playground/tree/main/packages/graphql-playground-html) | ||
without Electron and React environments. | ||
|
||
## Get Started | ||
|
||
```ts | ||
import { renderPlaygroundPage } from 'https://deno.land/x/[email protected]/graphiql/render.ts' | ||
|
||
const playground = renderPlaygroundPage({ | ||
endpoint: '/graphql', | ||
}) | ||
|
||
return new Response(playground, { | ||
headers: new Headers({ | ||
'Content-Type': 'text/html', | ||
}), | ||
}) | ||
``` | ||
|
||
[docs-badge]: https://img.shields.io/github/v/release/deno-libs/gql?label=Docs&logo=deno&style=for-the-badge&color=DD3FAA | ||
[docs]: https://doc.deno.land/https/deno.land/x/gql/graphiql/render.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts' | ||
import { expect } from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { renderPlaygroundPage } from './render.ts' | ||
|
||
describe('renderPlaygroundPage', () => { | ||
it('supports custom CDNs', () => { | ||
const html = renderPlaygroundPage({ cdnUrl: 'https://unpkg.com' }) | ||
|
||
expect(html).toContain( | ||
`https://unpkg.com/graphql-playground-react/build/static/css/index.css`, | ||
) | ||
expect(html).toContain( | ||
`https://unpkg.com/graphql-playground-react/build/favicon.png`, | ||
) | ||
expect(html).toContain( | ||
`https://unpkg.com/graphql-playground-react/build/static/js/middleware.js`, | ||
) | ||
}) | ||
it('supports custom versions of graphql-playground-react', () => { | ||
const html = renderPlaygroundPage({ version: '1.7.27' }) | ||
|
||
expect(html).toContain( | ||
`jsdelivr.net/npm/[email protected]/build/favicon.png`, | ||
) | ||
expect(html).toContain( | ||
`jsdelivr.net/npm/[email protected]/build/static/js/middleware.js`, | ||
) | ||
}) | ||
it('supports custom GraphQL endpoint', () => { | ||
const html = renderPlaygroundPage({ endpoint: '/grafql' }) | ||
|
||
expect(html).toContain(`/grafql`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
Status, | ||
STATUS_TEXT, | ||
} from './deps.ts' | ||
import { accepts } from 'https://deno.land/[email protected]/http/negotiation.ts' | ||
import { GQLOptions } from './types.ts' | ||
|
||
function toRequest<Req = Request, Ctx = unknown>( | ||
|
@@ -38,10 +39,8 @@ export function GraphQLHTTP< | |
|
||
return async function handleRequest(req: Request): Promise<Response> { | ||
try { | ||
const accept = req.headers.get('Accept') || '' | ||
|
||
if ( | ||
req.method === 'GET' && graphiql && accept.split(';')[0] === 'text/html' | ||
req.method === 'GET' && graphiql && accepts(req)[0] === 'text/html' | ||
) { | ||
const urlQuery = req.url.substring(req.url.indexOf('?')) | ||
const queryParams = new URLSearchParams(urlQuery) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { superdeno } from 'https://deno.land/x/[email protected]/mod.ts?target=deno' | ||
import { describe, it, run } from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts' | ||
import { | ||
buildSchema, | ||
GraphQLObjectType, | ||
GraphQLSchema, | ||
GraphQLString, | ||
} from 'npm:graphql@16.6' | ||
} from 'npm:graphql@16.8.1' | ||
import { GraphQLHTTP } from './mod.ts' | ||
|
||
const schema = buildSchema(` | ||
|
@@ -264,5 +264,3 @@ describe('GraphQLHTTP({ schema, rootValue })', () => { | |
}) | ||
}) | ||
}) | ||
|
||
run() |