From 03e3b50404076e49d1992a2cfaa82721ccae31c1 Mon Sep 17 00:00:00 2001 From: v1rtl Date: Thu, 18 Jul 2024 02:36:54 +0300 Subject: [PATCH] move to JSR, use superfetch in tests, update examples --- README.md | 4 +- deno.json | 7 + deno.lock | 348 +++++++++++++++++++++++++++++++------------- deps.ts | 6 +- examples/oak.ts | 8 +- examples/req-ctx.ts | 2 +- graphiql/render.ts | 5 +- mod.ts | 8 +- mod_test.ts | 291 ++++++++++++++++++------------------ 9 files changed, 418 insertions(+), 261 deletions(-) diff --git a/README.md b/README.md index a7b4975..bdc7737 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ for Deno. Based on [graphql-http](https://github.com/graphql/graphql-http). The simplest setup with `Deno.serve`: ```ts -import { GraphQLHTTP } from 'https://deno.land/x/gql@1.2.4/mod.ts' -import { makeExecutableSchema } from 'npm:@graphql-tools/schema@10.0.0' +import { GraphQLHTTP } from 'jsr:@deno-libs/gql@3.0.1/mod.ts' +import { makeExecutableSchema } from 'npm:@graphql-tools/schema@10.0.3' import { gql } from 'https://deno.land/x/graphql_tag@0.1.2/mod.ts' const typeDefs = gql` diff --git a/deno.json b/deno.json index 615ee1b..048d386 100644 --- a/deno.json +++ b/deno.json @@ -14,5 +14,12 @@ }, "test": { "exclude": ["audit_test.ts"] + }, + "name": "@deno-libs/gql", + "version": "3.0.1", + "exports": { + "./": "./mod.ts", + "./types": "./types.ts", + "./graphiql/render": "./graphiql/render.ts" } } diff --git a/deno.lock b/deno.lock index ad7f878..3c96094 100644 --- a/deno.lock +++ b/deno.lock @@ -2,64 +2,237 @@ "version": "3", "packages": { "specifiers": { + "jsr:@deno-libs/superfetch@2.0.1": "jsr:@deno-libs/superfetch@2.0.1", + "jsr:@oak/commons@0.11": "jsr:@oak/commons@0.11.0", + "jsr:@std/assert@0.223": "jsr:@std/assert@0.223.0", + "jsr:@std/assert@0.226": "jsr:@std/assert@0.226.0", + "jsr:@std/assert@1.0.0": "jsr:@std/assert@1.0.0", + "jsr:@std/assert@^0.223.0": "jsr:@std/assert@0.223.0", + "jsr:@std/assert@^0.224.0": "jsr:@std/assert@0.224.0", + "jsr:@std/bytes@0.223": "jsr:@std/bytes@0.223.0", + "jsr:@std/bytes@0.224": "jsr:@std/bytes@0.224.0", + "jsr:@std/bytes@^0.223.0": "jsr:@std/bytes@0.223.0", + "jsr:@std/crypto@0.223": "jsr:@std/crypto@0.223.0", + "jsr:@std/crypto@0.224": "jsr:@std/crypto@0.224.0", + "jsr:@std/encoding@1.0.0-rc.2": "jsr:@std/encoding@1.0.0-rc.2", + "jsr:@std/encoding@^0.223.0": "jsr:@std/encoding@0.223.0", + "jsr:@std/http@0.223": "jsr:@std/http@0.223.0", + "jsr:@std/http@0.224": "jsr:@std/http@0.224.5", + "jsr:@std/http@0.224.5": "jsr:@std/http@0.224.5", + "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1", + "jsr:@std/io@0.223": "jsr:@std/io@0.223.0", + "jsr:@std/media-types@0.223": "jsr:@std/media-types@0.223.0", + "jsr:@std/media-types@0.224": "jsr:@std/media-types@0.224.1", + "jsr:@std/media-types@1.0.1": "jsr:@std/media-types@1.0.1", + "jsr:@std/path@0.223": "jsr:@std/path@0.223.0", + "jsr:@std/testing@0.225.3": "jsr:@std/testing@0.225.3", + "npm:@graphql-tools/schema@10.0.3": "npm:@graphql-tools/schema@10.0.3_graphql@16.8.1", + "npm:@graphql-tools/schema@10.0.4-alpha-20240527111853-49b97e4daa4a7d40c7e0fac217d615f1e19165fe": "npm:@graphql-tools/schema@10.0.4-alpha-20240527111853-49b97e4daa4a7d40c7e0fac217d615f1e19165fe_graphql@16.8.1", + "npm:@types/node": "npm:@types/node@18.16.19", "npm:graphql-http@1.22.0": "npm:graphql-http@1.22.0_graphql@16.8.1", - "npm:graphql@16.8.1": "npm:graphql@16.8.1" + "npm:graphql-http@1.22.1": "npm:graphql-http@1.22.1_graphql@16.8.1", + "npm:graphql@16.8.1": "npm:graphql@16.8.1", + "npm:path-to-regexp@6.2.1": "npm:path-to-regexp@6.2.1" + }, + "jsr": { + "@deno-libs/superfetch@2.0.1": { + "integrity": "16f40d931baf3075e53e9d119a40bf3ddc49a55f8bd25f80a18baa36f29b2ce0", + "dependencies": [ + "jsr:@std/assert@1.0.0", + "jsr:@std/media-types@1.0.1" + ] + }, + "@oak/commons@0.11.0": { + "integrity": "07702bfe5c07cd8144c422022994da1f9fea466b185824f4be63a2b1b1a65125", + "dependencies": [ + "jsr:@std/assert@0.226", + "jsr:@std/bytes@0.224", + "jsr:@std/crypto@0.224", + "jsr:@std/http@0.224", + "jsr:@std/media-types@0.224" + ] + }, + "@std/assert@0.223.0": { + "integrity": "eb8d6d879d76e1cc431205bd346ed4d88dc051c6366365b1af47034b0670be24" + }, + "@std/assert@0.224.0": { + "integrity": "8643233ec7aec38a940a8264a6e3eed9bfa44e7a71cc6b3c8874213ff401967f" + }, + "@std/assert@0.226.0": { + "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3" + }, + "@std/assert@1.0.0": { + "integrity": "0e4f6d873f7f35e2a1e6194ceee39686c996b9e5d134948e644d35d4c4df2008", + "dependencies": [ + "jsr:@std/internal@^1.0.1" + ] + }, + "@std/bytes@0.223.0": { + "integrity": "84b75052cd8680942c397c2631318772b295019098f40aac5c36cead4cba51a8" + }, + "@std/bytes@0.224.0": { + "integrity": "a2250e1d0eb7d1c5a426f21267ab9bdeac2447fa87a3d0d1a467d3f7a6058e49" + }, + "@std/crypto@0.223.0": { + "integrity": "1aa9555ff56b09e197ad988ea200f84bc6781fd4fd83f3a156ee44449af93000", + "dependencies": [ + "jsr:@std/assert@^0.223.0", + "jsr:@std/encoding@^0.223.0" + ] + }, + "@std/crypto@0.224.0": { + "integrity": "154ef3ff08ef535562ef1a718718c5b2c5fc3808f0f9100daad69e829bfcdf2d", + "dependencies": [ + "jsr:@std/assert@^0.224.0" + ] + }, + "@std/encoding@0.223.0": { + "integrity": "2b5615a75e00337ce113f34cf2f9b8c18182c751a8dcc8b1a2c2fc0e117bef00" + }, + "@std/encoding@1.0.0-rc.2": { + "integrity": "160d7674a20ebfbccdf610b3801fee91cf6e42d1c106dd46bbaf46e395cd35ef" + }, + "@std/http@0.223.0": { + "integrity": "15ab8a0c5a7e9d5be017a15b01600f20f66602ceec48b378939fa24fcec522aa", + "dependencies": [ + "jsr:@std/assert@^0.223.0", + "jsr:@std/encoding@^0.223.0" + ] + }, + "@std/http@0.224.5": { + "integrity": "b03b5d1529f6c423badfb82f6640f9f2557b4034cd7c30655ba5bb447ff750a4", + "dependencies": [ + "jsr:@std/encoding@1.0.0-rc.2" + ] + }, + "@std/internal@1.0.1": { + "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6" + }, + "@std/io@0.223.0": { + "integrity": "2d8c3c2ab3a515619b90da2c6ff5ea7b75a94383259ef4d02116b228393f84f1", + "dependencies": [ + "jsr:@std/bytes@^0.223.0" + ] + }, + "@std/media-types@0.223.0": { + "integrity": "84684680c2eb6bc6d9369c6d6f26a49decaf2c7603ff531862dda575d9d6776e" + }, + "@std/media-types@0.224.1": { + "integrity": "9e69a5daed37c5b5c6d3ce4731dc191f80e67f79bed392b0957d1d03b87f11e1" + }, + "@std/media-types@1.0.1": { + "integrity": "f2ddc3497be0bd87ac0c9b9b26bb454f76bdc45e1b9a12146af47fab3ba2828c" + }, + "@std/path@0.223.0": { + "integrity": "593963402d7e6597f5a6e620931661053572c982fc014000459edc1f93cc3989", + "dependencies": [ + "jsr:@std/assert@^0.223.0" + ] + }, + "@std/testing@0.225.3": { + "integrity": "348c24d0479d44ab3dbb4f26170f242e19f24051b45935d4a9e7ca0ab7e37780" + } }, "npm": { + "@graphql-tools/merge@9.0.4_graphql@16.8.1": { + "integrity": "sha512-MivbDLUQ+4Q8G/Hp/9V72hbn810IJDEZQ57F01sHnlrrijyadibfVhaQfW/pNH+9T/l8ySZpaR/DpL5i+ruZ+g==", + "dependencies": { + "@graphql-tools/utils": "@graphql-tools/utils@10.3.2_graphql@16.8.1", + "graphql": "graphql@16.8.1", + "tslib": "tslib@2.6.3" + } + }, + "@graphql-tools/schema@10.0.3_graphql@16.8.1": { + "integrity": "sha512-p28Oh9EcOna6i0yLaCFOnkcBDQECVf3SCexT6ktb86QNj9idnkhI+tCxnwZDh58Qvjd2nURdkbevvoZkvxzCog==", + "dependencies": { + "@graphql-tools/merge": "@graphql-tools/merge@9.0.4_graphql@16.8.1", + "@graphql-tools/utils": "@graphql-tools/utils@10.3.2_graphql@16.8.1", + "graphql": "graphql@16.8.1", + "tslib": "tslib@2.6.3", + "value-or-promise": "value-or-promise@1.0.12" + } + }, + "@graphql-tools/schema@10.0.4-alpha-20240527111853-49b97e4daa4a7d40c7e0fac217d615f1e19165fe_graphql@16.8.1": { + "integrity": "sha512-zPx7P5tiL0hePU+GbzoZGBeQsXm2adZMOmZAVXJoXlQycjzPbhJiA1Lt1e0oNhmntnttZLydy8LllmyIrJo8Ag==", + "dependencies": { + "@graphql-tools/merge": "@graphql-tools/merge@9.0.4_graphql@16.8.1", + "@graphql-tools/utils": "@graphql-tools/utils@10.2.1-alpha-20240527111853-49b97e4daa4a7d40c7e0fac217d615f1e19165fe_graphql@16.8.1", + "graphql": "graphql@16.8.1", + "tslib": "tslib@2.6.3", + "value-or-promise": "value-or-promise@1.0.12" + } + }, + "@graphql-tools/utils@10.2.1-alpha-20240527111853-49b97e4daa4a7d40c7e0fac217d615f1e19165fe_graphql@16.8.1": { + "integrity": "sha512-LVEIQrxTVIaFutqXi+97mRLpsMJ6afeuy13+e2GJ20DlX4/bFVQIPHdzE5Zn3TH1OIuM9U9C75G4/bA4GEjT9w==", + "dependencies": { + "@graphql-typed-document-node/core": "@graphql-typed-document-node/core@3.2.0_graphql@16.8.1", + "cross-inspect": "cross-inspect@1.0.0", + "dset": "dset@3.1.3", + "graphql": "graphql@16.8.1", + "tslib": "tslib@2.6.3" + } + }, + "@graphql-tools/utils@10.3.2_graphql@16.8.1": { + "integrity": "sha512-iaqOHS4f90KNADBHqVsRBjKpM6iSvsUg1q5GhWMK03loYLaDzftrEwcsl0OkSSnRhJvAsT7q4q3r3YzRoV0v1g==", + "dependencies": { + "@graphql-typed-document-node/core": "@graphql-typed-document-node/core@3.2.0_graphql@16.8.1", + "cross-inspect": "cross-inspect@1.0.0", + "dset": "dset@3.1.3", + "graphql": "graphql@16.8.1", + "tslib": "tslib@2.6.3" + } + }, + "@graphql-typed-document-node/core@3.2.0_graphql@16.8.1": { + "integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==", + "dependencies": { + "graphql": "graphql@16.8.1" + } + }, + "@types/node@18.16.19": { + "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==", + "dependencies": {} + }, + "cross-inspect@1.0.0": { + "integrity": "sha512-4PFfn4b5ZN6FMNGSZlyb7wUhuN8wvj8t/VQHZdM4JsDcruGJ8L2kf9zao98QIrBPFCpdk27qst/AGTl7pL3ypQ==", + "dependencies": { + "tslib": "tslib@2.6.3" + } + }, + "dset@3.1.3": { + "integrity": "sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==", + "dependencies": {} + }, "graphql-http@1.22.0_graphql@16.8.1": { "integrity": "sha512-9RBUlGJWBFqz9LwfpmAbjJL/8j/HCNkZwPBU5+Bfmwez+1Ay43DocMNQYpIWsWqH0Ftv6PTNAh2aRnnMCBJgLw==", "dependencies": { "graphql": "graphql@16.8.1" } }, + "graphql-http@1.22.1_graphql@16.8.1": { + "integrity": "sha512-4Jor+LRbA7SfSaw7dfDUs2UBzvWg3cKrykfHRgKsOIvQaLuf+QOcG2t3Mx5N9GzSNJcuqMqJWz0ta5+BryEmXg==", + "dependencies": { + "graphql": "graphql@16.8.1" + } + }, "graphql@16.8.1": { "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", "dependencies": {} + }, + "path-to-regexp@6.2.1": { + "integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==", + "dependencies": {} + }, + "tslib@2.6.3": { + "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", + "dependencies": {} + }, + "value-or-promise@1.0.12": { + "integrity": "sha512-Z6Uz+TYwEqE7ZN50gwn+1LCVo9ZVrpxRPOhOLnncYkY1ZzOYtrX8Fwf/rFktZ8R5mJms6EZf5TqNOMeZmnPq9Q==", + "dependencies": {} } } }, "remote": { - "https://deno.land/std@0.213.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975", - "https://deno.land/std@0.213.0/assert/_diff.ts": "dcc63d94ca289aec80644030cf88ccbf7acaa6fbd7b0f22add93616b36593840", - "https://deno.land/std@0.213.0/assert/_format.ts": "0ba808961bf678437fb486b56405b6fefad2cf87b5809667c781ddee8c32aff4", - "https://deno.land/std@0.213.0/assert/assert.ts": "bec068b2fccdd434c138a555b19a2c2393b71dfaada02b7d568a01541e67cdc5", - "https://deno.land/std@0.213.0/assert/assert_almost_equals.ts": "8b96b7385cc117668b0720115eb6ee73d04c9bcb2f5d2344d674918c9113688f", - "https://deno.land/std@0.213.0/assert/assert_array_includes.ts": "1688d76317fd45b7e93ef9e2765f112fdf2b7c9821016cdfb380b9445374aed1", - "https://deno.land/std@0.213.0/assert/assert_equals.ts": "4497c56fe7d2993b0d447926702802fc0becb44e319079e8eca39b482ee01b4e", - "https://deno.land/std@0.213.0/assert/assert_exists.ts": "24a7bf965e634f909242cd09fbaf38bde6b791128ece08e33ab08586a7cc55c9", - "https://deno.land/std@0.213.0/assert/assert_false.ts": "6f382568e5128c0f855e5f7dbda8624c1ed9af4fcc33ef4a9afeeedcdce99769", - "https://deno.land/std@0.213.0/assert/assert_greater.ts": "4945cf5729f1a38874d7e589e0fe5cc5cd5abe5573ca2ddca9d3791aa891856c", - "https://deno.land/std@0.213.0/assert/assert_greater_or_equal.ts": "573ed8823283b8d94b7443eb69a849a3c369a8eb9666b2d1db50c33763a5d219", - "https://deno.land/std@0.213.0/assert/assert_instance_of.ts": "72dc1faff1e248692d873c89382fa1579dd7b53b56d52f37f9874a75b11ba444", - "https://deno.land/std@0.213.0/assert/assert_is_error.ts": "6596f2b5ba89ba2fe9b074f75e9318cda97a2381e59d476812e30077fbdb6ed2", - "https://deno.land/std@0.213.0/assert/assert_less.ts": "2b4b3fe7910f65f7be52212f19c3977ecb8ba5b2d6d0a296c83cde42920bb005", - "https://deno.land/std@0.213.0/assert/assert_less_or_equal.ts": "b93d212fe669fbde959e35b3437ac9a4468f2e6b77377e7b6ea2cfdd825d38a0", - "https://deno.land/std@0.213.0/assert/assert_match.ts": "ec2d9680ed3e7b9746ec57ec923a17eef6d476202f339ad91d22277d7f1d16e1", - "https://deno.land/std@0.213.0/assert/assert_not_equals.ts": "f3edda73043bc2c9fae6cbfaa957d5c69bbe76f5291a5b0466ed132c8789df4c", - "https://deno.land/std@0.213.0/assert/assert_not_instance_of.ts": "8f720d92d83775c40b2542a8d76c60c2d4aeddaf8713c8d11df8984af2604931", - "https://deno.land/std@0.213.0/assert/assert_not_match.ts": "b4b7c77f146963e2b673c1ce4846473703409eb93f5ab0eb60f6e6f8aeffe39f", - "https://deno.land/std@0.213.0/assert/assert_not_strict_equals.ts": "da0b8ab60a45d5a9371088378e5313f624799470c3b54c76e8b8abeec40a77be", - "https://deno.land/std@0.213.0/assert/assert_object_match.ts": "e85e5eef62a56ce364c3afdd27978ccab979288a3e772e6855c270a7b118fa49", - "https://deno.land/std@0.213.0/assert/assert_rejects.ts": "e9e0c8d9c3e164c7ac962c37b3be50577c5a2010db107ed272c4c1afb1269f54", - "https://deno.land/std@0.213.0/assert/assert_strict_equals.ts": "0425a98f70badccb151644c902384c12771a93e65f8ff610244b8147b03a2366", - "https://deno.land/std@0.213.0/assert/assert_string_includes.ts": "dfb072a890167146f8e5bdd6fde887ce4657098e9f71f12716ef37f35fb6f4a7", - "https://deno.land/std@0.213.0/assert/assert_throws.ts": "edddd86b39606c342164b49ad88dd39a26e72a26655e07545d172f164b617fa7", - "https://deno.land/std@0.213.0/assert/assertion_error.ts": "9f689a101ee586c4ce92f52fa7ddd362e86434ffdf1f848e45987dc7689976b8", - "https://deno.land/std@0.213.0/assert/equal.ts": "fae5e8a52a11d3ac694bbe1a53e13a7969e3f60791262312e91a3e741ae519e2", - "https://deno.land/std@0.213.0/assert/fail.ts": "f310e51992bac8e54f5fd8e44d098638434b2edb802383690e0d7a9be1979f1c", - "https://deno.land/std@0.213.0/assert/mod.ts": "325df8c0683ad83a873b9691aa66b812d6275fc9fec0b2d180ac68a2c5efed3b", - "https://deno.land/std@0.213.0/assert/unimplemented.ts": "47ca67d1c6dc53abd0bd729b71a31e0825fc452dbcd4fde4ca06789d5644e7fd", - "https://deno.land/std@0.213.0/assert/unreachable.ts": "38cfecb95d8b06906022d2f9474794fca4161a994f83354fd079cac9032b5145", - "https://deno.land/std@0.213.0/async/delay.ts": "8e1d18fe8b28ff95885e2bc54eccec1713f57f756053576d8228e6ca110793ad", - "https://deno.land/std@0.213.0/fmt/colors.ts": "aeaee795471b56fc62a3cb2e174ed33e91551b535f44677f6320336aabb54fbb", - "https://deno.land/std@0.213.0/http/server.ts": "6dce295abc169d0956ae00432441331b3425afad4d79e8b3475739be2f04d614", - "https://deno.land/std@0.213.0/http/status.ts": "ed61b4882af2514a81aefd3245e8df4c47b9a8e54929a903577643d2d1ebf514", - "https://deno.land/std@0.221.0/http/_negotiation/common.ts": "051a9f6edd1ed69507df89bbc16fc1b13b7654b9b8fd38072ec33ae4c185fc13", - "https://deno.land/std@0.221.0/http/_negotiation/encoding.ts": "fdedea1145c1dea3b3de2d5217e8eb927e764083eebc8c52d09a1ed3d9bb7a93", - "https://deno.land/std@0.221.0/http/_negotiation/language.ts": "300a5c586f844c97f246ab72c948e9fde9a8f45e92ec08e1cc9a9df80259e2a3", - "https://deno.land/std@0.221.0/http/_negotiation/media_type.ts": "87a1ecb22c1b268d0fa23d798e1ea238343505268cb1ff82bd038638de29ce31", - "https://deno.land/std@0.221.0/http/negotiation.ts": "d06ef2958ca712a7dbe4538eed6a46abfa2b87f8e150b7c89d83a6055dabd7cc", - "https://deno.land/std@0.221.0/http/status.ts": "ed61b4882af2514a81aefd3245e8df4c47b9a8e54929a903577643d2d1ebf514", "https://deno.land/std@0.221.0/testing/_test_suite.ts": "f10a8a6338b60c403f07a76f3f46bdc9f1e1a820c0a1decddeb2949f7a8a0546", "https://deno.land/std@0.221.0/testing/bdd.ts": "7a8ac58eded80e6fefa7cf7538927e88781cf5f247c04b35261c3213316e2dd0", "https://deno.land/std@0.97.0/fmt/colors.ts": "db22b314a2ae9430ae7460ce005e0a7130e23ae1c999157e3bb77cf55800f7e4", @@ -69,63 +242,42 @@ "https://deno.land/x/expect@v0.4.0/matchers.ts": "55acf74a3c4a308d079798930f05ab11da2080ec7acd53517193ca90d1296bf7", "https://deno.land/x/expect@v0.4.0/mock.ts": "562d4b1d735d15b0b8e935f342679096b64fe452f86e96714fe8616c0c884914", "https://deno.land/x/expect@v0.4.0/mod.ts": "0304d2430e1e96ba669a8495e24ba606dcc3d152e1f81aaa8da898cea24e36c2", - "https://deno.land/x/free_port@v1.2.0/mod.ts": "512646732aaea41fbfd1f210f3ae82660f38251777d189d290da331d0235a58e", - "https://deno.land/x/opine@2.3.4/src/methods.ts": "0481daecc6068d24e9e5391818baddf555ab803d39a465dcd259161f8bd8ee49", - "https://deno.land/x/opine@2.3.4/src/utils/mergeDescriptors.ts": "1fe498d4a1a8dcfd3570f9ca5e0647590d86d029b3c340bfcfdb57002851e41b", - "https://deno.land/x/superdeno@4.9.0/deps.ts": "acb88a5969aae0bcc82e053cb433cd183a10cc656495caa634b6e22a79156c4e", - "https://deno.land/x/superdeno@4.9.0/mod.ts?target=deno": "fa91c501867a4302a4bc92d63cbf934fe5475ebb7bf58335338e001147263c87", - "https://deno.land/x/superdeno@4.9.0/src/close.ts": "8bd4ab602ebbb048d06697d0c48c30be5f78ab9ad673850965e8014d78cca7a8", - "https://deno.land/x/superdeno@4.9.0/src/superagent.ts": "8f60187f9278b154ef6bccf09a5ff7d45f81103ad0ce02d45518a6bbe63ce764", - "https://deno.land/x/superdeno@4.9.0/src/superdeno.ts": "2e2cd4898961ac7688f0c2a4b210bf560a338f6601bd231d74bf8a0956880311", - "https://deno.land/x/superdeno@4.9.0/src/test.ts": "1ab3c8c98160af8c3b30e097809d5c57bdd38d7b42c703f3f170f8452ad06c0f", - "https://deno.land/x/superdeno@4.9.0/src/types.ts": "9a48cdfafad3cea2212e1be29cdd2055e7d3d467437c9048012797323335abbb", - "https://deno.land/x/superdeno@4.9.0/src/utils.ts": "09a2e65cc5cc2a261b885f0e66ee84e96e978181975a0728636d20e48b67bd89", - "https://deno.land/x/superdeno@4.9.0/src/xhrSham.js": "6a35aed77bbe98324fe3b4d7430463b7cd6d3b43445ffdccd1fc327dc59dd3c6", - "https://deno.land/x/superdeno@4.9.0/version.ts": "4f8ba8f2a6b201e8e96818d3ab5c43aef1db751523c4b79160500664b72f87de", + "https://deno.land/x/graphql_tag@0.1.2/deps.ts": "5696461c8bb42db7c83486db452e125f7cfdc62a2c628bb470a4447d934b90b3", + "https://deno.land/x/graphql_tag@0.1.2/mod.ts": "57fd56de5f7cbc66e23ce896cc8e99521d286e89969d83e09d960642b0a9d652", + "https://deno.land/x/oak@v16.1.0/application.ts": "c6361a3c3fb3607c5dfe1800b156f07b612979dc0498c746aeca54bb9f643a92", + "https://deno.land/x/oak@v16.1.0/body.ts": "0f8a6843720ea6cebba2132a5e4dda5a97bbd49e7fb64e96ade0b7c8009bba2d", + "https://deno.land/x/oak@v16.1.0/context.ts": "a93a5b41dde2ceb52232ae31b3496be76e8a42ea421a73d7cffe9e640adb8dfd", + "https://deno.land/x/oak@v16.1.0/deps.ts": "f960515f71091adecc3df5e2295b3acfc4f1c003e08be29fceec1f7616053433", + "https://deno.land/x/oak@v16.1.0/http_server_bun.ts": "cb3a66c735cd0533c4c3776b37ae627ab42344c82f91dff63e3030d9656fd3a0", + "https://deno.land/x/oak@v16.1.0/http_server_native.ts": "3bea00ebb9638203d2449fbf9a14a6b87f119bd45012f13282ececdf7b4c4242", + "https://deno.land/x/oak@v16.1.0/http_server_native_request.ts": "a4da6f4939736e6323720db2d4b0d19ff2e83f02e52ab1eea9ae80f2c047fa56", + "https://deno.land/x/oak@v16.1.0/http_server_node.ts": "9bb5291c15305b297fd634aa4c6b1d5054368f4b7a171d7c7c302c73eb2489ed", + "https://deno.land/x/oak@v16.1.0/middleware.ts": "4170180fe5009d2581a0bdc995e5953b90ccb5b1c3767f3eae8a4fe238b8bd81", + "https://deno.land/x/oak@v16.1.0/middleware/etag.ts": "310ed4ed01f2af5384ab78617c82a2bdd7f84d66539172e45ee16452846f0754", + "https://deno.land/x/oak@v16.1.0/middleware/proxy.ts": "a0b4964509d4320735ffbe52ae2629c78e302dd9b934fcf2ddf189d491469892", + "https://deno.land/x/oak@v16.1.0/middleware/serve.ts": "efceebd70afb73bcabe0a6a8981f3d8474a2f2f30e85b46761aee49e81bd9d6a", + "https://deno.land/x/oak@v16.1.0/mod.ts": "38e53e01e609583e843f3e2b2677de9872d23d68939ce0de85b402e7a8db01a7", + "https://deno.land/x/oak@v16.1.0/node_shims.ts": "4db1569b2b79b73f37c4d947f4aaa50a93e266d48fe67601c8a31af17a28884d", + "https://deno.land/x/oak@v16.1.0/request.ts": "1e7f2c338cd6889b616bbdc9e2062eac27acbffde05c685adfb1c60ecc80682a", + "https://deno.land/x/oak@v16.1.0/response.ts": "bc47174d3d797ffc802f40fba006c16de8390e776a36f6f4a4d4f58b278bf36f", + "https://deno.land/x/oak@v16.1.0/router.ts": "882f36a576e280b0d617cc174feca320f02deed77bdea8264444ba8b55cc0422", + "https://deno.land/x/oak@v16.1.0/send.ts": "c05e5985b356b568ae4954a40373f93451a3f8cc9ae8706c8b8879e5e0c8c86b", + "https://deno.land/x/oak@v16.1.0/testing.ts": "c879789ac721144c3dcad0a06f5afbe2cd94fb20afc32302992942a49a7def90", + "https://deno.land/x/oak@v16.1.0/types.ts": "cd4ccd3e182d0cba2117cd27f560267970470ab9c0ff6556cadd73f605193be7", + "https://deno.land/x/oak@v16.1.0/utils/clone_state.ts": "cf8989ddd56816b36ada253ae0acdbd46cdf3d68dbe674d2b66c46640fab3500", + "https://deno.land/x/oak@v16.1.0/utils/consts.ts": "137c4f73479f5e98a13153b9305f06f0d85df3cf2aacad2c9f82d4c1f3a2f105", + "https://deno.land/x/oak@v16.1.0/utils/create_promise_with_resolvers.ts": "de99e9a998162b929a011f8873eaf0895cf4742492b3ce6f6866d39217342523", + "https://deno.land/x/oak@v16.1.0/utils/decode_component.ts": "d3e2c40ecdd2fdb79761c6e9ae224cf01a4643f7c5f4c1e0b69698d43025261b", + "https://deno.land/x/oak@v16.1.0/utils/encode_url.ts": "c0ed6b318eb9523adeebba32eb9acd059c0f94d3511b2b9e3b024722d1b3dfb8", + "https://deno.land/x/oak@v16.1.0/utils/resolve_path.ts": "aa39d54a003b38fee55f340a0cba3f93a7af85b8ddd5fbfb049a98fc0109b36d", + "https://deno.land/x/oak@v16.1.0/utils/streams.ts": "6d55543fdeddc3c9c6f512de227b9b33ff4b0ec5e320edc109f0cbf9bef8963f", + "https://deno.land/x/oak@v16.1.0/utils/type_guards.ts": "a1b42aa4c431c4c07d3f8a45a2142020f86d5a3e1e319af94fdf2f4c6c72465f", + "https://esm.sh/graphql@16.6.0/language/ast#=": "3370c36acfd7dc994d7f2242361dbc538b7b239f0cb41603f97a5d67273f5255", + "https://esm.sh/graphql@16.6.0/language/parser#=": "38b1158134aed40573b9885cc5f3b020fe8b60c75aa8b32420388c577615b97a", "https://esm.sh/v135/cssfilter@0.0.10/denonext/cssfilter.mjs": "b2dec5f4b51c7574509f04305aa54e33f9de336d66eade79f05552312f18f40b", + "https://esm.sh/v135/graphql@16.6.0/denonext/language/ast.js": "1c8cc697db4ec96d354496fa69a2d6552ec5801a6c3bdbe5505f369d872d594c", + "https://esm.sh/v135/graphql@16.6.0/denonext/language/parser.js": "82063e5ee234089909652e04ccd9f0e1c0670c04ac6db896099a638ae759b182", "https://esm.sh/v135/xss@1.0.15/denonext/xss.mjs": "b8f597b39cbfc8b9f9b0d73b5b8bb46ee08dd7a9b7eadccb1b524ea54617b031", - "https://esm.sh/xss@1.0.15/": "0d8e27aed5ce31e760e17b57bbc6f95a0146751387a2be56d5263297d92ac387", - "https://jspm.dev/npm:call-bind@1.0.5!cjs": "09f8399c727fc1e9d58fdafc0a729b45bf37b7ee0c11d9d0b39abe37ac42ccf5", - "https://jspm.dev/npm:call-bind@1.0.5/callBound!cjs": "55fa05e2b115eeaef9ff684e3df12de253e6644a40ad09b5722f3a9a8df8f645", - "https://jspm.dev/npm:call-bind@1/callBound!cjs": "9cf2ef160025d392767618c2f0cb72d32cf14caa3fbeb493c6df9bde9d7fca8d", - "https://jspm.dev/npm:component-emitter@1!cjs": "26c2994a5fcac1cd9156b00be96c5e2f006dd76338095a96006ac3a47c6c327d", - "https://jspm.dev/npm:component-emitter@1.3.0!cjs": "757cafefb0bf5639f3f90b2267a7d168e03631e731c2a79fca847b735695e196", - "https://jspm.dev/npm:define-data-property@1!cjs": "37b65cb06c826730306a5f766de69da37b96076c96ea11a47667e9429623f937", - "https://jspm.dev/npm:define-data-property@1.1.1!cjs": "4ac6fa4b9d7ba7ccc83ffa350c58112ee878a450a97375217f66508d5673c822", - "https://jspm.dev/npm:fast-safe-stringify@2!cjs": "d8dd0803af23f037ffb44c13e18333131af27ebe582f55fd498b6e3c8f6d5a9d", - "https://jspm.dev/npm:fast-safe-stringify@2.1.1!cjs": "8a14a2de8a07a719c74aa63ffa5ff635fc55e9ee5d5a79fbc2e087dc4aa1940e", - "https://jspm.dev/npm:function-bind@1!cjs": "73fbc50bf85e8a6ca150609e98c396301c1ae5a1603e50ce8c64e95f646e0ce0", - "https://jspm.dev/npm:function-bind@1.1.2!cjs": "bbb663bc4e50f400a8ca0de9e0bfdaaa7022695f86b2806a48dc1afc5b4195a8", - "https://jspm.dev/npm:function-bind@1.1.2/implementation!cjs": "ebdc0ec85854db19d7e21081b368891394f86e21c6d786273c327762cb46ea6a", - "https://jspm.dev/npm:get-intrinsic@1!cjs": "f6d9266edc586632e8f6d8d6c5ca28fb2c0d5ee9c9d9252df9aafd57eda9fcea", - "https://jspm.dev/npm:get-intrinsic@1.2.2!cjs": "723fcebc493a45d5af8ecb366020a6cc2ce9bd4759bad699c1172015cb193f65", - "https://jspm.dev/npm:gopd@1!cjs": "c220469947b77de2c5e4b115beda16397bf6133c5b873b8e24e85b902ee6dc82", - "https://jspm.dev/npm:gopd@1.0.1!cjs": "b38da4f4b49cfef31e3aa8d62fdd136cf0fe99a5df6c603a426f97248f3cf4ab", - "https://jspm.dev/npm:has-property-descriptors@1!cjs": "b1a828f75a22a5614b136dd3da1be98cc744a2cd6bfed9bd8c338a8d51a570d1", - "https://jspm.dev/npm:has-property-descriptors@1.0.1!cjs": "f8da64823507f597f3cb44a2f3576e350df72e1033ef5e7a5b30d771e81c0819", - "https://jspm.dev/npm:has-proto@1!cjs": "78a2914e5525d531426c5d69fd5aa23671ec359c6c527b9791327f60ad1b6682", - "https://jspm.dev/npm:has-proto@1.0.1!cjs": "0a9d605f1d310f859265780011d6343a7869cadf3a9e02fd6cc949c2924b528c", - "https://jspm.dev/npm:has-symbols@1!cjs": "48faf647d225b64fa235ccc3e5a848e72221b0230935e421066a5de39aa89c3a", - "https://jspm.dev/npm:has-symbols@1.0.3!cjs": "36965f84e4e0ea1abeddb6928d0719a2648e61ceb9825df185b40d05cddb64df", - "https://jspm.dev/npm:has-symbols@1.0.3/shams!cjs": "669673e1dc7691c0b397580760121d57f3a5c5101dd70be2e8dd7d2a044de2e9", - "https://jspm.dev/npm:hasown@2!cjs": "9a39af846b167cae93b7a40f1ba4c97255bb5b07a1481da853a29bb68d24e603", - "https://jspm.dev/npm:hasown@2.0.0!cjs": "f52fd2477e345530f759465a984023f23d8261c4a54970e619daf1da6a2e85f5", - "https://jspm.dev/npm:object-inspect@1!cjs": "dc197b471ed55ecf2eabeb8da9aaee277e97831e65192531432a4ec2346211d9", - "https://jspm.dev/npm:object-inspect@1.13.1!cjs": "cec116e5c2b7d6b75e178d2541d70475d716ad912e3d5599e5c2d97284a9cb3e", - "https://jspm.dev/npm:qs@6!cjs": "210de1e090ac836c2495c19dfea88fc74b49de1b308241f8c9490d27ab6e0195", - "https://jspm.dev/npm:qs@6.11.2!cjs": "5da52fff60f7b1a6b1c73cdea2d9fc5d5588fa6c551b2a0ea2a1ebbb2a5e559f", - "https://jspm.dev/npm:qs@6.11.2/_/e71c21de.js": "cfe49eb949fb7291803f1ed2f4c0a244b8fca3b6936f5082fc97581a0663e427", - "https://jspm.dev/npm:qs@6.11.2/lib/stringify!cjs": "35d39c5871af151efe9ccca8e4ebecbf0282f97287b5fad56ebac369f69c2581", - "https://jspm.dev/npm:set-function-length@1!cjs": "b4c766d874ba261ff0c11aa18a6bf4510ecf8da09a7219da83a62772e0bc1b41", - "https://jspm.dev/npm:set-function-length@1.1.1!cjs": "f52607660d1f50e19e645ab49e6a4adf27fa4ae909867ec9950e993c430e4ca1", - "https://jspm.dev/npm:side-channel@1!cjs": "a07dfe7165af0d7f916d089490c38839397abcd8b218e4566b270858c9a0ea04", - "https://jspm.dev/npm:side-channel@1.0.4!cjs": "db65b31b6f9e67d57f04e26d71eb5b376306f5a89ab46fae1278c3ffefb19663", - "https://jspm.dev/npm:superagent@6.1.0!cjs": "fcf1c0b17cb3ff899b59ae178fc4ab74ad3b592d7fa8b44b16394001758e3176", - "https://jspm.dev/npm:superagent@6.1.0/lib/agent-base!cjs": "cfe465965a55d80114d835143717413945d0bbc46355d0f7f8200a89902ed006", - "https://jspm.dev/npm:superagent@6.1.0/lib/is-object!cjs": "95f67ff49b42fd5e82114b9d54a4b3fe1ac98813aed7ceaf53d314983f59820a", - "https://jspm.dev/npm:superagent@6.1.0/lib/request-base!cjs": "e361c341aa75d7417c918bc8fb697d0ccf96101e039dd2f00e5e45c01c534caa", - "https://jspm.dev/npm:superagent@6.1.0/lib/response-base!cjs": "00ac549f34d73c2753caa798aa7eb781051179013e3418ff0868a1e1904a8913", - "https://jspm.dev/npm:superagent@6.1.0/lib/utils!cjs": "ea706523553983c96ef4ab2f191c61c53fb8b78ad8ff2472b48f1385e896c030", - "https://jspm.dev/superagent@6.1.0": "4b3082d71252c42abd3930d85d1f3c4b2e937e0fab2b5f1c9d19eac20dea89a9" + "https://esm.sh/xss@1.0.15": "0d8e27aed5ce31e760e17b57bbc6f95a0146751387a2be56d5263297d92ac387" } } diff --git a/deps.ts b/deps.ts index a1626bd..54fbceb 100644 --- a/deps.ts +++ b/deps.ts @@ -12,7 +12,5 @@ export { type Request as RawRequest, type RequestParams, } from 'npm:graphql-http@1.22.0' -export { - STATUS_TEXT, - type StatusCode, -} from 'https://deno.land/std@0.221.0/http/status.ts' +export { STATUS_TEXT, type StatusCode } from 'jsr:@std/http@0.224.5/status' +export { accepts } from 'jsr:@std/http@0.224.5/negotiation' diff --git a/examples/oak.ts b/examples/oak.ts index 41a4626..9155555 100644 --- a/examples/oak.ts +++ b/examples/oak.ts @@ -1,9 +1,9 @@ import { Application, - Middleware, - Request as OakRequest, + type Middleware, + type Request as OakRequest, Router, -} from 'https://deno.land/x/oak@14.2.0/mod.ts' +} from 'https://deno.land/x/oak@v16.1.0/mod.ts' import { GraphQLHTTP } from '../mod.ts' import { makeExecutableSchema } from 'npm:@graphql-tools/schema@10.0.3' import { gql } from 'https://deno.land/x/graphql_tag@0.1.2/mod.ts' @@ -27,7 +27,7 @@ const schema = makeExecutableSchema({ typeDefs, resolvers }) const handleGraphQL: Middleware = async (ctx) => { // cast Oak request into a normal Request const req = new Request(ctx.request.url.toString(), { - body: ctx.request.originalRequest.getBody().body, + body: await ctx.request.body.blob(), headers: ctx.request.headers, method: ctx.request.method, }) diff --git a/examples/req-ctx.ts b/examples/req-ctx.ts index e1d084c..5f8e742 100644 --- a/examples/req-ctx.ts +++ b/examples/req-ctx.ts @@ -1,7 +1,7 @@ import { GraphQLHTTP } from '../mod.ts' import { makeExecutableSchema } from 'npm:@graphql-tools/schema@10.0.3' import { gql } from 'https://deno.land/x/graphql_tag@0.1.2/mod.ts' -import type { Request as GQLRequest } from 'npm:graphql-http@1.22.0' +import type { Request as GQLRequest } from 'npm:graphql-http@1.22.1' const typeDefs = gql` type Query { diff --git a/graphiql/render.ts b/graphiql/render.ts index 4d09eb3..742230e 100644 --- a/graphiql/render.ts +++ b/graphiql/render.ts @@ -1,4 +1,4 @@ -import { filterXSS } from 'https://esm.sh/xss@1.0.15/' +import { filterXSS } from 'https://esm.sh/xss@1.0.15' import { getLoadingMarkup } from './markup.ts' export interface MiddlewareOptions { @@ -56,6 +56,7 @@ export interface EditorColours { } export interface IntrospectionResult { + // deno-lint-ignore no-explicit-any __schema: any } @@ -148,7 +149,7 @@ export function renderPlaygroundPage(options: RenderPageOptions) { } if (!extendedOptions.endpoint && !extendedOptions.configString) { console.warn( - `WARNING: You didn't provide an endpoint and don't have a .graphqlconfig. Make sure you have at least one of them.`, + `WARNING: You didn't provide an endpoint and don't have a config. Make sure you have at least one of them.`, ) } else if (extendedOptions.endpoint) { extendedOptions.endpoint = filter(extendedOptions.endpoint || '') diff --git a/mod.ts b/mod.ts index d059ede..129c0e3 100644 --- a/mod.ts +++ b/mod.ts @@ -1,12 +1,12 @@ import { + accepts, createHandler, - OperationContext, - RawRequest, + type OperationContext, + type RawRequest, STATUS_TEXT, type StatusCode, } from './deps.ts' -import { accepts } from 'https://deno.land/std@0.221.0/http/negotiation.ts' -import { GQLOptions } from './types.ts' +import type { GQLOptions } from './types.ts' function toRequest( req: Pick, diff --git a/mod_test.ts b/mod_test.ts index 78fb6b1..8d9d30f 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -1,11 +1,6 @@ -import { superdeno } from 'https://deno.land/x/superdeno@4.9.0/mod.ts?target=deno' -import { describe, it } from 'https://deno.land/std@0.221.0/testing/bdd.ts' -import { - buildSchema, - GraphQLObjectType, - GraphQLSchema, - GraphQLString, -} from 'npm:graphql@16.8.1' +import { makeFetch } from 'jsr:@deno-libs/superfetch@2.0.1' +import { describe, it } from 'jsr:@std/testing@0.225.3/bdd' +import { buildSchema } from 'npm:graphql@16.8.1' import { GraphQLHTTP } from './mod.ts' const schema = buildSchema(` @@ -22,152 +17,146 @@ const app = GraphQLHTTP({ schema, rootValue }) describe('GraphQLHTTP({ schema, rootValue })', () => { it('should send 400 on malformed request query', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/').expect(400, { + const res = await fetch('/', { + headers: { 'Content-Type': 'application/json' }, + }) + res.expectBody({ 'errors': [{ 'message': 'Missing query' }], }) + res.expectStatus(400) }) it('should send unsupported media type on empty request body', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request.post('/').expect(415) + const res = await fetch('/', { + method: 'POST', + }) + res.expectStatus(415) }) + it('should send resolved POST GraphQL query', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .post('/') - .send({ - 'query': '\n{\n hello\n}', - }) - .expect(200, { data: { hello: 'Hello World!' } }) + const res = await fetch('/', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + query: '\n{\n hello\n}', + }), + }) + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) }) + it('should send resolved GET GraphQL query', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/?query={hello}').expect( - 200, - { data: { hello: 'Hello World!' } }, - ) + const res = await fetch('/?query={hello}') + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) }) + it('should send resolved GET GraphQL query when Accept is application/json', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .get('/?query={hello}') - .set('Accept', 'application/json') - .expect(200, { data: { hello: 'Hello World!' } }) - .expect('Content-Type', 'application/json; charset=utf-8') + const res = await fetch('/?query={hello}', { + headers: { Accept: 'application/json' }, + }) + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) + res.expectHeader('Content-Type', 'application/json; charset=utf-8') }) + it('should send resolved GET GraphQL query when Accept is */*', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .get('/?query={hello}') - .set('Accept', '*/*') - .expect(200, { data: { hello: 'Hello World!' } }) - .expect('Content-Type', 'application/json; charset=utf-8') + const res = await fetch('/?query={hello}', { + headers: { Accept: '*/*' }, + }) + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) + res.expectHeader('Content-Type', 'application/json; charset=utf-8') }) + it('should send 406 not acceptable when Accept is other (text/html)', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/?query={hello}').set('Accept', 'text/html').expect( - 406, - 'Not Acceptable', - ) + const res = await fetch('/?query={hello}', { + headers: { Accept: 'text/html' }, + }) + res.expectStatus(406) + res.expectBody('Not Acceptable') }) + it('should send 406 not acceptable when Accept is other (text/css)', async () => { - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/?query={hello}').set('Accept', 'text/css').expect( - 406, - 'Not Acceptable', - ) - }) - it('should pass req obj to server context', async () => { - type Context = { request: Request } - - const app = GraphQLHTTP({ - schema: new GraphQLSchema({ - query: new GraphQLObjectType({ - name: 'Query', - fields: { - 'hello': { - type: GraphQLString, - resolve: (_root, _args, { request: { url } }: Context) => - `Request from ${url.slice(url.lastIndexOf('/'))}`, - }, - }, - }), - }), - context: (req) => ({ request: req.raw }), + const res = await fetch('/?query={hello}', { + headers: { Accept: 'text/css' }, }) - - const request = superdeno(app) - - await request - .post('/') - .send({ - 'query': '\n{\n hello\n}', - 'variables': {}, - 'operationName': null, - }) - .expect(200, { data: { hello: 'Request from /' } }) + res.expectStatus(406) + res.expectBody('Not Acceptable') }) describe('graphiql', () => { it('should allow query GET requests when set to false', async () => { const app = GraphQLHTTP({ graphiql: false, schema, rootValue }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/?query={hello}').expect( - 200, - { data: { hello: 'Hello World!' } }, - ) + const res = await fetch('/?query={hello}') + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) }) + it('should allow query GET requests when set to true', async () => { const app = GraphQLHTTP({ graphiql: true, schema, rootValue }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/?query={hello}').expect( - 200, - { data: { hello: 'Hello World!' } }, - ) + const res = await fetch('/?query={hello}') + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) }) + it('should send 406 when Accept is only text/html when set to false', async () => { const app = GraphQLHTTP({ graphiql: false, schema, rootValue }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/').set('Accept', 'text/html').expect( - 406, - 'Not Acceptable', - ) + const res = await fetch('/', { + headers: { Accept: 'text/html' }, + }) + res.expectStatus(406) + res.expectBody('Not Acceptable') }) + it('should render a playground when Accept does include text/html when set to true', async () => { const app = GraphQLHTTP({ graphiql: true, schema, rootValue }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .get('/?query={hello}') - .set('Accept', 'text/html;*/*') - .expect(200) - .expect('Content-Type', 'text/html') + const res = await fetch('/?query={hello}', { + headers: { Accept: 'text/html;*/*' }, + }) + res.expectStatus(200) + res.expectHeader('Content-Type', 'text/html') }) + it('should render a playground if graphiql is set to true', async () => { const app = GraphQLHTTP({ graphiql: true, schema, rootValue }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request.get('/').set('Accept', 'text/html').expect(200).expect( - 'Content-Type', - 'text/html', - ) + const res = await fetch('/', { + headers: { Accept: 'text/html' }, + }) + res.expectStatus(200) + res.expectHeader('Content-Type', 'text/html') }) + describe('playgroundOptions', () => { it('supports custom favicon', async () => { const app = GraphQLHTTP({ @@ -179,19 +168,20 @@ describe('GraphQLHTTP({ schema, rootValue })', () => { }, }) - const request = superdeno(app) - - await request - .get('/') - .set('Accept', 'text/html') - .expect(200) - .expect('Content-Type', 'text/html') - .expect( - new RegExp( - '', - ), - ) + const fetch = makeFetch(app) + + const res = await fetch('/', { + headers: { Accept: 'text/html' }, + }) + res.expectStatus(200) + res.expectHeader('Content-Type', 'text/html') + res.expectBody( + new RegExp( + '', + ), + ) }) + it('supports custom title', async () => { const app = GraphQLHTTP({ graphiql: true, @@ -202,15 +192,16 @@ describe('GraphQLHTTP({ schema, rootValue })', () => { }, }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .get('/') - .set('Accept', 'text/html') - .expect(200) - .expect('Content-Type', 'text/html') - .expect(new RegExp('Hello gql!')) + const res = await fetch('/', { + headers: { Accept: 'text/html' }, + }) + res.expectStatus(200) + res.expectHeader('Content-Type', 'text/html') + res.expectBody(new RegExp('Hello gql!')) }) + it('adds React CDN links if env is React', async () => { const app = GraphQLHTTP({ graphiql: true, @@ -221,46 +212,54 @@ describe('GraphQLHTTP({ schema, rootValue })', () => { }, }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .get('/') - .set('Accept', 'text/html') - .expect(200) - .expect('Content-Type', 'text/html') - .expect(new RegExp('https://unpkg.com')) + const res = await fetch('/', { + headers: { Accept: 'text/html' }, + }) + res.expectStatus(200) + res.expectHeader('Content-Type', 'text/html') + res.expectBody(new RegExp('unpkg.com')) }) }) }) + describe('headers', () => { it('should pass custom headers to response', async () => { const app = GraphQLHTTP({ schema, rootValue, headers: { Key: 'Value' } }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .post('/') - .send({ - 'query': '\n{\n hello\n}', - 'variables': {}, - 'operationName': null, - }) - .expect(200, { data: { hello: 'Hello World!' } }) - .expect('Key', 'Value') + const res = await fetch('/', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + query: '\n{\n hello\n}', + variables: {}, + operationName: null, + }), + }) + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) + res.expectHeader('Key', 'Value') }) + it('does not error with empty header object', async () => { const app = GraphQLHTTP({ schema, rootValue, headers: {} }) - const request = superdeno(app) + const fetch = makeFetch(app) - await request - .post('/') - .send({ - 'query': '\n{\n hello\n}', - 'variables': {}, - 'operationName': null, - }) - .expect(200, { data: { hello: 'Hello World!' } }) + const res = await fetch('/', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + query: '\n{\n hello\n}', + variables: {}, + operationName: null, + }), + }) + res.expectBody({ data: { hello: 'Hello World!' } }) + res.expectStatus(200) }) }) })