Skip to content

Commit

Permalink
fix: cache-bust requests using @prismicio/client's updated `graphQL…
Browse files Browse the repository at this point in the history
…Fetch()` (#41)

* fix: cache-bust requests using `@prismicio/client`'s updated `graphQLFetch()`

* chore: update `@prismicio/client`
  • Loading branch information
angeloashmore authored Mar 10, 2022
1 parent 2b6069e commit b91c19e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava"
},
"dependencies": {
"@prismicio/client": "^6.3.0"
"@prismicio/client": "^6.4.1"
},
"devDependencies": {
"@apollo/client": "^3.5.8",
Expand Down
2 changes: 1 addition & 1 deletion src/createPrismicLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const createPrismicLink = (config: PrismicLinkConfig): ApolloLink => {

return createHttpLink({
uri,
fetch: client.graphqlFetch,
fetch: client.graphQLFetch,
useGETForQueries: true,
...options,
});
Expand Down
13 changes: 9 additions & 4 deletions test/createPrismicLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const repositoryResponse: Partial<prismicT.Repository> = {
},
],
};
const ref = repositoryResponse.refs?.[0].ref as string;

test("creates an HTTP Link from a repositoryName", async (t) => {
const repositoryName = "qwerty";
Expand All @@ -68,6 +69,7 @@ test("creates an HTTP Link from a repositoryName", async (t) => {
return new Response(JSON.stringify(repositoryResponse));
} else if (`${instance.origin}${instance.pathname}` === uri) {
t.is(instance.searchParams.get("query"), compressedQuery);
t.is(instance.searchParams.get("ref"), ref);

return new Response(
JSON.stringify({
Expand All @@ -88,7 +90,7 @@ test("creates an HTTP Link from a repositoryName", async (t) => {

await executeRequest(link, { query });

t.plan(1);
t.plan(2);
});

test("supports only a uri option", async (t) => {
Expand All @@ -110,6 +112,7 @@ test("supports only a uri option", async (t) => {
return new Response(JSON.stringify(repositoryResponse));
} else if (`${instance.origin}${instance.pathname}` === uri) {
t.is(instance.searchParams.get("query"), compressedQuery);
t.is(instance.searchParams.get("ref"), ref);

return new Response(
JSON.stringify({
Expand All @@ -130,7 +133,7 @@ test("supports only a uri option", async (t) => {

await executeRequest(link, { query });

t.plan(1);
t.plan(2);
});

test("throws if neither a repositoryName or uri option is given", (t) => {
Expand Down Expand Up @@ -169,6 +172,7 @@ test("supports custom API endpoint (for Rest API)", async (t) => {
return new Response(JSON.stringify(repositoryResponse));
} else if (`${instance.origin}${instance.pathname}` === uri) {
t.is(instance.searchParams.get("query"), compressedQuery);
t.is(instance.searchParams.get("ref"), ref);

return new Response(
JSON.stringify({
Expand All @@ -190,7 +194,7 @@ test("supports custom API endpoint (for Rest API)", async (t) => {

await executeRequest(link, { query });

t.plan(1);
t.plan(2);
});

test("supports custom GraphQL endpoint", async (t) => {
Expand All @@ -212,6 +216,7 @@ test("supports custom GraphQL endpoint", async (t) => {
return new Response(JSON.stringify(repositoryResponse));
} else if (`${instance.origin}${instance.pathname}` === uri) {
t.is(instance.searchParams.get("query"), compressedQuery);
t.is(instance.searchParams.get("ref"), ref);

return new Response(
JSON.stringify({
Expand All @@ -233,5 +238,5 @@ test("supports custom GraphQL endpoint", async (t) => {

await executeRequest(link, { query });

t.plan(1);
t.plan(2);
});

0 comments on commit b91c19e

Please sign in to comment.