Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(data): add custom header support to data schema client #12559

Merged
merged 33 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
065c7f6
feat(data): add custom header support to data schema client
david-mcafee Nov 10, 2023
b48236b
Merge branch 'main' into tb-headers
david-mcafee Nov 10, 2023
0176020
add support for custom headers for individual requests
david-mcafee Nov 10, 2023
3b15680
update individual request headers; update comments; refactor utils an…
david-mcafee Nov 10, 2023
4fa8c45
Merge branch 'main' into tb-headers
david-mcafee Nov 10, 2023
2119013
cleanup
david-mcafee Nov 10, 2023
8355a5f
move 'CustomHeader' type to 'data-schema-types' package
david-mcafee Nov 10, 2023
4deafac
add unit tests
david-mcafee Nov 10, 2023
0439b07
Merge branch 'main' into tb-headers
david-mcafee Nov 10, 2023
83beba7
add comment
david-mcafee Nov 10, 2023
2945fb5
update comment
david-mcafee Nov 10, 2023
ef6a406
Merge branch 'main' into tb-headers
david-mcafee Nov 10, 2023
6c5a9c5
Merge branch 'main' into tb-headers
david-mcafee Nov 11, 2023
3b88039
Merge branch 'main' into tb-headers
david-mcafee Nov 11, 2023
5c029b2
update data-schema dependency
david-mcafee Nov 11, 2023
de5a0ca
custom header subscription tests
david-mcafee Nov 11, 2023
f0bbb18
ts strict mode updates
david-mcafee Nov 13, 2023
0a8c91e
Merge branch 'main' into tb-headers
david-mcafee Nov 13, 2023
0a62e0a
formatting
david-mcafee Nov 14, 2023
3cf2059
update tsconfig
david-mcafee Nov 14, 2023
18da01c
pull in type updates
david-mcafee Nov 14, 2023
0272dac
minor fix
david-mcafee Nov 14, 2023
73a34c6
Merge branch 'main' into tb-headers
david-mcafee Nov 14, 2023
63c4b5a
cleanup
david-mcafee Nov 14, 2023
d37dd15
test fix
david-mcafee Nov 14, 2023
a4f1769
custom header subscription fixes
david-mcafee Nov 14, 2023
08a5d44
AppSyncRealTimeProvider updates
david-mcafee Nov 15, 2023
1961e83
fix type for AWSAppSyncRealTimeProvider
david-mcafee Nov 15, 2023
1ec3a56
add comment
david-mcafee Nov 15, 2023
6a8651e
real time provider type updates
david-mcafee Nov 15, 2023
2a72796
real time provider fix
david-mcafee Nov 15, 2023
0af3e15
include auth token in functional headers
david-mcafee Nov 15, 2023
72749fd
Merge branch 'main' into tb-headers
david-mcafee Nov 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
"GraphQLAPI.test.ts",
"generateClient.test.ts",
"--runInBand",
"--testTimeout",
"600000", // 10 min timeout so jest doesn't error while we're stepping through code
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-nextjs/src/api/generateServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { NextServer } from '../types';
import { createServerRunnerForAPI } from './createServerRunnerForAPI';
import { getAmplifyConfig } from '../utils';
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
import { CustomHeaders } from '@aws-amplify/data-schema-types';

type CookiesClientParams = {
cookies: NextServer.ServerComponentContext['cookies'];
Expand Down Expand Up @@ -116,7 +117,7 @@ export function generateServerClientUsingReqRes<
const wrappedGraphql = (
contextSpec: AmplifyServer.ContextSpec,
options: GraphQLOptionsV6,
additionalHeaders?: { [key: string]: string }
additionalHeaders?: CustomHeaders
) => {
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
return prevGraphql.call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,27 @@ describe('AWSAppSyncRealTimeProvider', () => {
);
});

test('authenticating with AWS_LAMBDA/custom w/ custom header function', async () => {
expect.assertions(1);

provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: 'none',
additionalHeaders: async () => ({
Authorization: 'test',
}),
})
.subscribe({ error: () => {} });

await fakeWebSocketInterface?.readyForUse;

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

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

Expand Down
Loading
Loading