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): Add granular user agent for Ai #13835

Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d95573e
feat: Add ability to override api user agent with granular actions
cshfang Sep 13, 2024
799f178
Removed customUserAgentDetails and introduced new symbol to override …
yuhengshs Sep 20, 2024
df29334
moved symbol to constant file, export AiActions
yuhengshs Sep 20, 2024
d7ad0e3
update symbol to have fallback, added unit test for graphql, consolid…
yuhengshs Sep 20, 2024
820b676
moved symbol to Platform/index.ts
yuhengshs Sep 20, 2024
36b0100
added internal ts-doc for UA Override symbol
yuhengshs Sep 23, 2024
14f440b
added delete conversation as AiAction #8
yuhengshs Sep 24, 2024
90994db
Bump up bundle size, added GraphQLOptionsWithOverride
yuhengshs Sep 25, 2024
7a47e40
Merge branch 'main' into yuhengsh-feat/add-granular-user-agent
yuhengshs Sep 25, 2024
8f5c837
replace GraphQLOptionsWithOverride as type guards
yuhengshs Sep 25, 2024
40d8bdb
import IUAO symbol from data-schema in api package
yuhengshs Sep 26, 2024
0eb4fd8
Merge branch 'main' into yuhengsh-feat/add-granular-user-agent
yuhengshs Sep 26, 2024
a3f988d
bump up data-schma version to suppoert User Agent Override for AiAction
yuhengshs Sep 27, 2024
9c4b98c
bump up generateClient bundle size
yuhengshs Sep 27, 2024
a2734a5
avoid usage of let and shorten unit test to just focus on User Agent …
yuhengshs Sep 27, 2024
2885249
reorganized enum orders for AiAction
yuhengshs Sep 27, 2024
ca1a7f3
update data-schema version
yuhengshs Sep 27, 2024
c1078f9
update yarn.lock
yuhengshs Sep 30, 2024
865847e
Merge branch 'main' into yuhengsh-feat/add-granular-user-agent
yuhengshs Oct 1, 2024
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
43 changes: 32 additions & 11 deletions packages/api-graphql/src/GraphQLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import { Observable } from 'rxjs';
import { GraphQLOptions, GraphQLResult } from './types';
import { InternalGraphQLAPIClass } from './internals/InternalGraphQLAPI';

interface GraphQLOptionsWithOverride extends GraphQLOptions {
[INTERNAL_USER_AGENT_OVERRIDE]?: CustomUserAgentDetails;
function isGraphQLOptionsWithOverride(
options: GraphQLOptions,
): options is GraphQLOptions & {
[INTERNAL_USER_AGENT_OVERRIDE]: CustomUserAgentDetails;
} {
return INTERNAL_USER_AGENT_OVERRIDE in options;
}

export const graphqlOperation = (
Expand Down Expand Up @@ -47,16 +51,33 @@ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
options: GraphQLOptions,
additionalHeaders?: CustomHeaders,
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
const {
[INTERNAL_USER_AGENT_OVERRIDE]: internalUserAgentOverride,
...cleanOptions
} = options as GraphQLOptionsWithOverride;
let cleanOptions = options;
let userAgentDetails: CustomUserAgentDetails;

return super.graphql(amplify, cleanOptions, additionalHeaders, {
category: Category.API,
action: ApiAction.GraphQl,
...internalUserAgentOverride,
});
if (isGraphQLOptionsWithOverride(options)) {
const {
[INTERNAL_USER_AGENT_OVERRIDE]: internalUserAgentOverride,
...rest
} = options;
userAgentDetails = {
yuhengshs marked this conversation as resolved.
Show resolved Hide resolved
category: Category.API,
action: ApiAction.GraphQl,
...internalUserAgentOverride,
};
cleanOptions = rest;
} else {
userAgentDetails = {
category: Category.API,
action: ApiAction.GraphQl,
};
}

return super.graphql(
amplify,
cleanOptions,
additionalHeaders,
userAgentDetails,
);
}

/**
Expand Down
Loading