Skip to content

Commit

Permalink
feat(client): url option function with request params as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Aug 5, 2022
1 parent b97a9c0 commit 99d9086
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docs/interfaces/ClientOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ ___

### url

**url**: `string` \| () => `string` \| `Promise`<`string`\>
**url**: `string` \| (`request`: [`RequestParams`](RequestParams.md)) => `string` \| `Promise`<`string`\>

URL of the GraphQL over HTTP server to connect.

Expand All @@ -164,3 +164,6 @@ resolves.

A good use-case for having a function is when using the URL for authentication,
where subsequent requests (due to auth) may have a refreshed identity token.

Function receives the request params. Useful for example, to ease up debugging and DevTools
navigation you might want to use the operation name in the URL's search params (`/graphql?MyQuery`).
7 changes: 5 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export interface ClientOptions {
*
* A good use-case for having a function is when using the URL for authentication,
* where subsequent requests (due to auth) may have a refreshed identity token.
*
* Function receives the request params. Useful for example, to ease up debugging and DevTools
* navigation you might want to use the operation name in the URL's search params (`/graphql?MyQuery`).
*/
url: string | (() => Promise<string> | string);
url: string | ((request: RequestParams) => Promise<string> | string);
/**
* Indicates whether the user agent should send cookies from the other domain in the case
* of cross-origin requests.
Expand Down Expand Up @@ -217,7 +220,7 @@ export function createClient(options: ClientOptions): Client {
try {
const url =
typeof options.url === 'function'
? await options.url()
? await options.url(request)
: options.url;
if (control.signal.aborted) return;

Expand Down

0 comments on commit 99d9086

Please sign in to comment.