2
votes

I have a GraphQL API built with Apollo Engine on Node.JS, and this API includes a /graphiql endpoint to the graphql playground where I can generate queries like the example below:

query {
  canonical(ref: "") {
    id
  }
}

My question is: how can I generate a sharable URL which contains the query above. (for example: htttp://gql-endpoint.com/graphiql?query=...

The motivation behind this is to generate URLs that, upon request, open the graphiql interface and display the query side by side with the response.

Thank you for your help.

1

1 Answers

1
votes

Turns out, there is actually a very simple solution for this: You can copy the query as is in the graphical interface, and add it to the ?query= query string parameter.

For example, given the endpoint http://gql-endpoint.com/graphiql, the query would look as follows:

http://gql-endpoint.com/graphiql?query=COPY_PASTE_YOUR_QUERY_HERE.

Using the example above, this would look something like:

http://gql-endpoint.com/graphiql?query=query {
  canonical(ref: "") {
    id
  }
}

Which, when used on the browser, results in an escaped URL, something like:

http://gql-endpoint.com/graphiql?query=query%20{%20canonical(ref:%20%22%22)%20{%20id%20}%20}