@@ -6,6 +6,8 @@ import * as typedQueries from './fixtures/with-types/queries';
6
6
import * as typedSubscriptions from './fixtures/with-types/subscriptions' ;
7
7
import { expectGet } from './utils/expects' ;
8
8
import { InternalGraphQLAPIClass } from '../src/internals/InternalGraphQLAPI' ;
9
+ import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils' ;
10
+ import { INTERNAL_USER_AGENT_OVERRIDE } from '@aws-amplify/data-schema/runtime' ;
9
11
10
12
import {
11
13
__amplify ,
@@ -1614,4 +1616,58 @@ describe('API test', () => {
1614
1616
const subscribeOptions = spyon_appsync_realtime . mock . calls [ 0 ] [ 0 ] ;
1615
1617
expect ( subscribeOptions ) . toBe ( resolvedUrl ) ;
1616
1618
} ) ;
1619
+ test ( 'graphql method handles INTERNAL_USER_AGENT_OVERRIDE correctly' , async ( ) => {
1620
+ Amplify . configure ( {
1621
+ API : {
1622
+ GraphQL : {
1623
+ defaultAuthMode : 'apiKey' ,
1624
+ apiKey : 'FAKE-KEY' ,
1625
+ endpoint : 'https://localhost/graphql' ,
1626
+ region : 'local-host-h4x' ,
1627
+ } ,
1628
+ } ,
1629
+ } ) ;
1630
+
1631
+ const mockPost = jest . fn ( ) . mockResolvedValue ( {
1632
+ body : {
1633
+ json : ( ) => ( { data : { test : 'result' } } ) ,
1634
+ } ,
1635
+ } ) ;
1636
+ ( raw . GraphQLAPI as any ) . _api . post = mockPost ;
1637
+
1638
+ const graphqlOptions = {
1639
+ query : 'query TestQuery { test }' ,
1640
+ variables : { id : 'some-id' } ,
1641
+ authMode : 'apiKey' as GraphQLAuthMode ,
1642
+ [ INTERNAL_USER_AGENT_OVERRIDE ] : {
1643
+ category : 'CustomCategory' ,
1644
+ action : 'CustomAction' ,
1645
+ } ,
1646
+ } ;
1647
+
1648
+ await client . graphql ( graphqlOptions ) ;
1649
+
1650
+ // Check if the INTERNAL_USER_AGENT_OVERRIDE was properly handled
1651
+ expect ( mockPost ) . toHaveBeenCalledWith (
1652
+ expect . anything ( ) ,
1653
+ expect . objectContaining ( {
1654
+ options : expect . objectContaining ( {
1655
+ headers : expect . objectContaining ( {
1656
+ 'x-amz-user-agent' : expect . stringContaining (
1657
+ 'CustomCategory/CustomAction' ,
1658
+ ) ,
1659
+ } ) ,
1660
+ } ) ,
1661
+ } ) ,
1662
+ ) ;
1663
+ // Ensure the INTERNAL_USER_AGENT_OVERRIDE was not passed along in the options
1664
+ expect ( mockPost ) . not . toHaveBeenCalledWith (
1665
+ expect . anything ( ) ,
1666
+ expect . objectContaining ( {
1667
+ options : expect . objectContaining ( {
1668
+ [ INTERNAL_USER_AGENT_OVERRIDE ] : expect . anything ( ) ,
1669
+ } ) ,
1670
+ } ) ,
1671
+ ) ;
1672
+ } ) ;
1617
1673
} ) ;
0 commit comments