Skip to content

Commit

Permalink
fix(url-loader): do not pass credentials: same-origin by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Sep 5, 2022
1 parent bd20dd0 commit 2926a27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/ninety-taxis-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-tools/url-loader': minor
---

Do not pass credentials: same-origin by default because it is already default per spec

This prevents an error like (The 'credentials' field on 'RequestInitializerDict' is not implemented.) on the environments that don't support `credentials` flag like CF Workers.
11 changes: 4 additions & 7 deletions packages/loaders/url/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
timeout?: number;
/**
* Request Credentials (default: 'same-origin')
* You can pass `disable` if you don't want this to be set in `Request`
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
*/
credentials?: RequestCredentials | 'disable';
credentials?: RequestCredentials;
/**
* Connection Parameters for WebSockets connection
*/
Expand Down Expand Up @@ -361,8 +360,6 @@ export class UrlLoader implements Loader<LoadFromUrlOptions> {
}, options.timeout);
}

const credentials = options?.credentials !== 'disable' ? options?.credentials || 'same-origin' : null;

return new ValueOrPromise(() => {
switch (method) {
case 'GET':
Expand All @@ -374,7 +371,7 @@ export class UrlLoader implements Loader<LoadFromUrlOptions> {
finalUrl,
{
method: 'GET',
...(credentials != null ? { credentials } : {}),
...(options?.credentials != null ? { credentials: options.credentials } : {}),
headers,
signal: controller?.signal,
},
Expand All @@ -390,7 +387,7 @@ export class UrlLoader implements Loader<LoadFromUrlOptions> {
endpoint,
{
method: 'POST',
...(credentials != null ? { credentials } : {}),
...(options?.credentials != null ? { credentials: options.credentials } : {}),
body,
headers: {
...headers,
Expand All @@ -408,7 +405,7 @@ export class UrlLoader implements Loader<LoadFromUrlOptions> {
endpoint,
{
method: 'POST',
...(credentials != null ? { credentials } : {}),
...(options?.credentials != null ? { credentials: options.credentials } : {}),
body: JSON.stringify(requestBody),
headers: {
'content-type': 'application/json',
Expand Down

1 comment on commit 2926a27

@vercel
Copy link

@vercel vercel bot commented on 2926a27 Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.