From 003c76941bab3e4e2b0448310bb6c8e6a3277824 Mon Sep 17 00:00:00 2001 From: Bill Min Date: Thu, 2 May 2024 18:29:21 -0400 Subject: [PATCH] feat: add fetch imp as third param in custom fetch --- README.md | 4 +- .../renders.expected/loading.0.html | 5 ++ .../renders.expected/loading.1.html | 13 ++++ .../renders.expected/loading.2.html | 9 +++ .../isomorphic-fetch-imp/components/app.marko | 12 ++++ .../fixtures/isomorphic-fetch-imp/index.marko | 13 ++++ .../gql-query/__tests__/server.test.ts | 4 ++ src/node_modules/@internal/client/browser.ts | 12 +++- src/node_modules/@internal/client/node.ts | 65 ++++++++++++------- 9 files changed, 112 insertions(+), 25 deletions(-) create mode 100644 src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.0.html create mode 100644 src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.1.html create mode 100644 src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.2.html create mode 100644 src/components/gql-query/__tests__/fixtures/isomorphic-fetch-imp/components/app.marko create mode 100644 src/components/gql-query/__tests__/fixtures/isomorphic-fetch-imp/index.marko diff --git a/README.md b/README.md index b800342..daaccec 100644 --- a/README.md +++ b/README.md @@ -108,10 +108,12 @@ This attribute allows you to pass a custom `fetch` implementation. In the following example we'll add a token to each fetch request that our Client sends to our GraphQL API. +> Note: fetchImp as third parameter is the default implementation based on environment. It is `fetch` API in browser and `make-fetch-happen` in node. + ```marko { + fetch=((resource, options, fetchImp) => { const token = getToken(); return fetch(resource, { ...options, diff --git a/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.0.html b/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.0.html new file mode 100644 index 0000000..d9eed76 --- /dev/null +++ b/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.0.html @@ -0,0 +1,5 @@ +
+
\ No newline at end of file diff --git a/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.1.html b/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.1.html new file mode 100644 index 0000000..8a37fa4 --- /dev/null +++ b/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.1.html @@ -0,0 +1,13 @@ +
+
+ \ No newline at end of file diff --git a/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.2.html b/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.2.html new file mode 100644 index 0000000..6f301af --- /dev/null +++ b/src/components/gql-query/__tests__/__snapshots__/isomorphic-fetch-imp/renders.expected/loading.2.html @@ -0,0 +1,9 @@ +
+ + Hello world! + +
+