0

I've spent the last hour or so looking through the GraphIQL guides and readme's. I don't see any documentation about how to direct the client to a specific endpoint/port. I am runni

I am running graphiql from the root of the project, locally. I have a graphql server running my backend and I just want to direct GraphIQL to it.

user3738936
  • 936
  • 8
  • 22
  • Have you considered `GraphQL Playground` as an alternative? https://github.com/prisma-labs/graphql-playground – goto Jul 04 '20 at 23:52

1 Answers1

0

The docs outline all the props that are available on the GraphiQL React component. If you have a GraphQLSchema instance available, you can pass that directly in as the schema parameter. Otherwise, you just point your fetcher at the appropriate URL:

async function graphQLFetcher(graphQLParams) {
  return fetch(YOUR_GRAPHQL_ENDPOINT_URL, {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(graphQLParams),
  })
  .then(response => response.json())
  .catch(() => response.text());
}

ReactDOM.render(<GraphiQL fetcher={graphQLFetcher} />, document.body);
Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183