From e750bc082de98d2931467f39af135b11798ebb6e Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 21 Mar 2023 18:45:49 +0100 Subject: [PATCH] docs(recipes): audit servers with Deno (#63) --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 9e9fe2cb..3f58e641 100644 --- a/README.md +++ b/README.md @@ -736,6 +736,36 @@ for (const audit of serverAudits({ +
+🔗 Audit for servers usage in Deno environment + +```ts +import { serverAudits } from 'npm:graphql-http'; + +for (const audit of serverAudits({ + url: 'http://localhost:4000/graphql', + fetchFn: fetch, +})) { + Deno.test(audit.name, async () => { + const result = await audit.fn(); + if (result.status === 'error') { + throw result.reason; + } + if (result.status === 'warn') { + console.warn(result.reason); // or throw if you want full compliance (warnings are not requirements) + } + // Avoid leaking resources + if ('body' in result && result.body instanceof ReadableStream) { + await result.body.cancel(); + } + }); +} +``` + +Put the above contents in a file and run it with `deno test --allow-net`. + +
+ ## Only [GraphQL over HTTP](https://graphql.github.io/graphql-over-http/) This 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 file uploads, @stream/@defer directives and subscriptions).