@@ -3,6 +3,7 @@ import { Store } from '@ngrx/store';
33import {
44 CreateActionOptions ,
55 CreatePanelOptions ,
6+ PluginContext ,
67 PluginContextGenerator ,
78 PluginWindowState ,
89} from 'altair-graphql-core/build/plugin/context/context.interface' ;
@@ -24,6 +25,7 @@ import * as fromRoot from '../../../store';
2425
2526import * as queryActions from '../../../store/query/query.action' ;
2627import * as variablesActions from '../../../store/variables/variables.action' ;
28+ import * as headersActions from '../../../store/headers/headers.action' ;
2729import * as localActions from '../../../store/local/local.action' ;
2830import * as settingsActions from '../../../store/settings/settings.action' ;
2931
@@ -32,6 +34,7 @@ import { first, take } from 'rxjs/operators';
3234import { ThemeRegistryService } from '../../../services/theme/theme-registry.service' ;
3335import { NotifyService } from '../../../services/notify/notify.service' ;
3436import { SubscriptionProviderRegistryService } from '../../subscriptions/subscription-provider-registry.service' ;
37+ import { headerListToMap , headerMapToList } from '../../../utils/headers' ;
3538import {
3639 AltairPanel ,
3740 AltairPanelLocation ,
@@ -54,7 +57,7 @@ export class PluginContextService implements PluginContextGenerator {
5457 private notifyService : NotifyService
5558 ) { }
5659
57- createContext ( pluginName : string , plugin : AltairPlugin ) {
60+ createContext ( pluginName : string , plugin : AltairPlugin ) : PluginContext {
5861 const self = this ;
5962 const log = ( msg : string ) => debug . log ( `PLUGIN[${ pluginName } ]: ${ msg } ` ) ;
6063 const eventBus = this . pluginEventService . group ( ) ;
@@ -161,6 +164,20 @@ export class PluginContextService implements PluginContextGenerator {
161164 new queryActions . SendIntrospectionQueryRequestAction ( windowId )
162165 ) ;
163166 } ,
167+ async setHeader ( windowId , key , value ) {
168+ log ( `setting header: ${ key } ` ) ;
169+ const state = await this . getWindowState ( windowId ) ;
170+ const headers = state ?. headers ?? [ ] ;
171+ const obj = headerListToMap ( headers ) ;
172+
173+ obj [ key ] = value ;
174+ self . store . dispatch (
175+ new headersActions . SetHeadersAction (
176+ { headers : headerMapToList ( obj ) } ,
177+ windowId
178+ )
179+ ) ;
180+ } ,
164181 addSubscriptionProvider ( providerData : SubscriptionProviderData ) {
165182 log ( `adding subscription provider: ${ providerData . id } ` ) ;
166183 self . subscriptionProviderRegistryService . addProviderData (
0 commit comments