Skip to content

Commit 70bacc6

Browse files
committed
Adds support for local GraphQL endpoints
Why are these changes being introduced: * Rather than our playground always pointing at a specific version of TIMDEX, this has the playground use the "local" version, which can include local development, PR builds, stage, prod, etc. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TIMX-183 How does this address that need: * Updates to the latest version of the GraphiQL playground example code * Adds support for using the running, or "local", version of the GraphQL endpoint Document any side effects to this change: * There was an attempt to create a script to auto download the various 3rd Party CDN resources and serve them localy. Most of the files worked fine, but `graphiql.min.js` consistently downloaded in a state in which whitespace was replaced with non-whitespace characters. It felt like an encoding issue, but it was unclear how to resolve it. Loading the file in a browser as text and copy/pasting worked, but downloading directly in a browser, using curl, wget, or http CLI all led to the same behavior. As such, relying on the 3rd Party CDN at this time seemed prudent.
1 parent 86ba39f commit 70bacc6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

public/playground.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@
128128
// use fetch, and could instead implement graphQLFetcher however you like,
129129
// as long as it returns a Promise or Observable.
130130
function graphQLFetcher(graphQLParams) {
131-
// When working locally, the example expects a GraphQL server at the path /graphql.
132-
// In a PR preview, it connects to the Star Wars API externally.
133-
// Change this to point wherever you host your GraphQL server.
134-
const isDev = window.location.hostname.match(/localhost$/);
135-
const api = isDev ? "/graphql" : "https://swapi-graphql.netlify.com/.netlify/functions/index";
131+
// This should allow for the playground to use the local GraphQL endpoint in all of our environments,
132+
// including localhost, pr builds, staging environments, and production.
133+
// For this to work, we must host the static playground.html on the same server that runs the graphql endpoint.
134+
// In other words, even those this is a static page, we can't host it in our documentation server or we'd need
135+
// to rework how the graphql endpoint is calculated.
136+
const api = location.origin + "/graphql";
137+
console.log(api);
136138
return fetch(api, {
137139
method: "post",
138140
headers: {

0 commit comments

Comments
 (0)