Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
fix: ssr strip whitespace fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
birkir committed Apr 11, 2019
1 parent 3b9bab0 commit 3f843c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/gatsby-source-prismic-graphql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "gatsby-source-prismic-graphql",
"version": "3.0.4",
"version": "3.0.5",
"description": "Source data from Prismic with GraphQL",
"main": "index.js",
"types": "./types/index.d.ts",
Expand Down
15 changes: 15 additions & 0 deletions packages/gatsby-source-prismic-graphql/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export function getCookies() {
return parseQueryString(document.cookie, ';');
}

export function fetchStripQueryWhitespace(url: string, ...args: any) {
const [hostname, qs = ''] = url.split('?');
const queryString = parseQueryString(qs);
if (queryString.has('query')) {
queryString.set('query', String(queryString.get('query')).replace(/\s+/g, ' '));
}
const updatedQs = Array.from(queryString)
.map(n => n.map(j => encodeURIComponent(j)).join('='))
.join('&');
const updatedUrl = `${hostname}?${updatedQs}`;

return fetch(updatedUrl, ...args);
}

/**
* Apollo Link for Prismic
* @param options Options
Expand Down Expand Up @@ -65,6 +79,7 @@ export function PrismicLink({ uri, accessToken, ...rest }: IPrismicLinkArgs) {
uri,
useGETForQueries: true,
...rest,
fetch: fetchStripQueryWhitespace,
});

return prismicLink.concat(httpLink);
Expand Down

0 comments on commit 3f843c2

Please sign in to comment.