-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
closes #33 There is a new third parameter on the `request` an `rawRequest` methods for passing headers particular to that request. For example: ```js import { GraphQLClient } from 'graphql-request' const client = new GraphQLClient(endpoint) const query = gql` query getMovie($title: String!) { Movie(title: $title) { releaseDate actors { name } } } ` const variables = { title: 'Inception', } const requestHeaders = { authorization: 'Bearer MY_TOKEN' } // Overrides the clients headers with the passed values const data = await client.request(query, variables, requestHeaders) ```
- Loading branch information
Showing
4 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { GraphQLClient } from '../src' | ||
;(async function () { | ||
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr' | ||
|
||
const client = new GraphQLClient(endpoint, { | ||
headers: { | ||
authorization: 'Bearer MY_TOKEN', | ||
}, | ||
}) | ||
|
||
const query = /* GraphQL */ ` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
const requestHeaders = { | ||
authorization: 'Bearer MY_TOKEN_2', | ||
'x-custom': 'foo' | ||
} | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
|
||
const data = await client.request<TData>(query, {}, requestHeaders) | ||
console.log(JSON.stringify(data, undefined, 2)) | ||
})().catch((error) => console.error(error)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters