Skip to content

Commit

Permalink
add passing header info to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Nov 19, 2023
1 parent 9fdf28c commit 65bf5bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ or play around with it in a live playground

By default API will return schema as `JSON`

### Passing `Headers`

If you're using a GraphQL endpoint that requires an API key, you can pass it in the `headers` like so:
```json
{
"X-API-KEY-NAME": "<api-key-name>",
"X-API-KEY-VALUE": "<api-key-value>"
}
```

Example
```json
{
"X-API-KEY": "Authorization",
"X-API-VALUE": "Bearer 1234567890"
}
```

To use the `playground`/`graphiql` endpoint when you need to pass headers (i.e., api key), you can `curl` the endpoint and save the response locally to an `html` file then simply open the file in your browser.

Example
```sh
curl --request 'GET' \
--url 'https://introspect.lagon.dev/graphiql/https://spacex-production.up.railway.app' \
--header 'X-API-KEY-NAME: Authorization' \
--header 'X-API-KEY-VALUE: Bearer loremipsum420' \
--output 'playground.html'
```

### Examples

Fetch Uniswap `GraphQL` API schema as `JSON`:
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function fetchJsonSchema({
})
})
const json = await response.json()

if (!response.ok) {
throw new Error(`Failed to fetch from ${url} - ${response.statusText}: ${json}`)
}
Expand Down

0 comments on commit 65bf5bb

Please sign in to comment.