Skip to content

Commit 99d9086

Browse files
committed
feat(client): url option function with request params as argument
1 parent b97a9c0 commit 99d9086

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

docs/interfaces/ClientOptions.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ ___
154154

155155
### url
156156

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

159159
URL of the GraphQL over HTTP server to connect.
160160

@@ -164,3 +164,6 @@ resolves.
164164

165165
A good use-case for having a function is when using the URL for authentication,
166166
where subsequent requests (due to auth) may have a refreshed identity token.
167+
168+
Function receives the request params. Useful for example, to ease up debugging and DevTools
169+
navigation you might want to use the operation name in the URL's search params (`/graphql?MyQuery`).

src/client.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ export interface ClientOptions {
2222
*
2323
* A good use-case for having a function is when using the URL for authentication,
2424
* where subsequent requests (due to auth) may have a refreshed identity token.
25+
*
26+
* Function receives the request params. Useful for example, to ease up debugging and DevTools
27+
* navigation you might want to use the operation name in the URL's search params (`/graphql?MyQuery`).
2528
*/
26-
url: string | (() => Promise<string> | string);
29+
url: string | ((request: RequestParams) => Promise<string> | string);
2730
/**
2831
* Indicates whether the user agent should send cookies from the other domain in the case
2932
* of cross-origin requests.
@@ -217,7 +220,7 @@ export function createClient(options: ClientOptions): Client {
217220
try {
218221
const url =
219222
typeof options.url === 'function'
220-
? await options.url()
223+
? await options.url(request)
221224
: options.url;
222225
if (control.signal.aborted) return;
223226

0 commit comments

Comments
 (0)