Skip to content

Commit

Permalink
feat(data): pass request options to custom header functions (#12572)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mcafee committed Dec 13, 2023
1 parent 9ad889a commit b092100
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
// Optionally specify a single test file to run/debug:
"generateClient.test.ts",
"AWSAppSyncRealTimeProvider.test.ts",
"--runInBand",
"--testTimeout",
"600000", // 10 min timeout so jest doesn't error while we're stepping through code
Expand Down
27 changes: 27 additions & 0 deletions packages/api-graphql/__tests__/AWSAppSyncRealTimeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,33 @@ describe('AWSAppSyncRealTimeProvider', () => {
);
});

test('authenticating with AWS_LAMBDA/custom w/ custom header function that accepts request options', async () => {
expect.assertions(2);

provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: 'none',
additionalHeaders: async requestOptions => {
expect(requestOptions).toEqual(
expect.objectContaining({
queryString: '',
url: 'ws://localhost:8080',
})
);
return { Authorization: 'test' };
},
})
.subscribe({ error: () => {} });

await fakeWebSocketInterface?.readyForUse;

expect(loggerSpy).toHaveBeenCalledWith(
'DEBUG',
'Authenticating with "none"'
);
});

test('authenticating with AWS_LAMBDA/custom without Authorization', async () => {
expect.assertions(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,63 @@ exports[`generateClient basic model operations - custom client and request heade
]
`;

exports[`generateClient basic model operations - custom client and request headers can create() - with custom client header functions that pass requestOptions 1`] = `
[
[
{
"abortController": AbortController {},
"options": {
"body": {
"query": "mutation ($input: CreateTodoInput!) {
createTodo(input: $input) {
id
name
description
status
tags
createdAt
updatedAt
todoMetaId
owner
}
}
",
"variables": {
"input": {
"description": "something something",
"name": "some name",
},
},
},
"headers": {
"X-Api-Key": "FAKE-KEY",
"rq-method": "POST",
"rq-qs": "mutation ($input: CreateTodoInput!) {
createTodo(input: $input) {
id
name
description
status
tags
createdAt
updatedAt
todoMetaId
owner
}
}
",
"rq-url": "https://localhost/graphql",
"x-amz-user-agent": "aws-amplify/latest api/latest framework/latest",
},
"signingServiceInfo": undefined,
"withCredentials": undefined,
},
"url": "https://localhost/graphql",
},
],
]
`;

exports[`generateClient basic model operations - custom client and request headers can create() - with custom client headers 1`] = `
[
[
Expand Down Expand Up @@ -2856,6 +2913,63 @@ exports[`generateClient basic model operations - custom client and request heade
]
`;

exports[`generateClient basic model operations - custom client and request headers can create() - with custom request header function that accept requestOptions 1`] = `
[
[
{
"abortController": AbortController {},
"options": {
"body": {
"query": "mutation ($input: CreateTodoInput!) {
createTodo(input: $input) {
id
name
description
status
tags
createdAt
updatedAt
todoMetaId
owner
}
}
",
"variables": {
"input": {
"description": "something something",
"name": "some name",
},
},
},
"headers": {
"X-Api-Key": "FAKE-KEY",
"rq-method": "POST",
"rq-qs": "mutation ($input: CreateTodoInput!) {
createTodo(input: $input) {
id
name
description
status
tags
createdAt
updatedAt
todoMetaId
owner
}
}
",
"rq-url": "https://localhost/graphql",
"x-amz-user-agent": "aws-amplify/latest api/latest framework/latest",
},
"signingServiceInfo": undefined,
"withCredentials": undefined,
},
"url": "https://localhost/graphql",
},
],
]
`;

exports[`generateClient basic model operations - custom client and request headers can create() - with custom request headers 1`] = `
[
[
Expand Down
Loading

0 comments on commit b092100

Please sign in to comment.