From f5e8e96089bbe42170a4a77253dfe56f75abb5c2 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 21 Mar 2023 15:32:36 +0100 Subject: [PATCH 1/3] Add recipe to audit servers with Deno --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 9e9fe2cb..a32c6f8c 100644 --- a/README.md +++ b/README.md @@ -736,6 +736,31 @@ for (const audit of serverAudits({ +
+🔗 Audit for servers usage in Deno environment + +```ts +import { serverAudits } from 'https://esm.sh/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) + } + // result.status === 'ok' + }); +} +``` + +
+ ## 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). From 1dd821c5f573c025643cfe77f22953f40e1cd3b9 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 21 Mar 2023 16:35:13 +0100 Subject: [PATCH 2/3] npm, command --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a32c6f8c..82d1f4f8 100644 --- a/README.md +++ b/README.md @@ -740,7 +740,7 @@ for (const audit of serverAudits({ 🔗 Audit for servers usage in Deno environment ```ts -import { serverAudits } from 'https://esm.sh/graphql-http'; +import { serverAudits } from 'npm:graphql-http'; for (const audit of serverAudits({ url: 'http://localhost:4000/graphql', @@ -759,6 +759,8 @@ for (const audit of serverAudits({ } ``` +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/) From 5363fa318f5c0852c266ad0e57c10ba191066784 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 21 Mar 2023 18:30:31 +0100 Subject: [PATCH 3/3] Avoid leaking resources --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82d1f4f8..3f58e641 100644 --- a/README.md +++ b/README.md @@ -754,7 +754,10 @@ for (const audit of serverAudits({ if (result.status === 'warn') { console.warn(result.reason); // or throw if you want full compliance (warnings are not requirements) } - // result.status === 'ok' + // Avoid leaking resources + if ('body' in result && result.body instanceof ReadableStream) { + await result.body.cancel(); + } }); } ```