I am using Apollo angular client to call API in angular my some API's are POST type and some are GET type and I want to change API method type as per API(GET or POST) I am new with this so please help me. my code :
export class AppModule {
constructor(
apollo: Apollo,
private httpLink: HttpLink
) {
const auth = setContext((_, { headers }) => {
const token = sessionStorage.getItem('token');
if (!token) {
return {};
} else {
return {
headers: headers.append('Authorization', token)
};
}
});
const http = this.httpLink.create({ uri: '/api/graph', method: 'GET' });
apollo.create({
link: auth.concat(http),
cache: new InMemoryCache()
});
}
}
Api method(GET Type):
constructor(private router: Router, private apollo: Apollo, private appService: AppService) { } login() { this.apollo.query({query: MyQuery }) .subscribe((data) => { if (data['data']) { console.log(err); } }, err => { console.log(err); }); }
API Method(POST Type) code:
this.apollo.query( { query: MyQuery }) .subscribe((data) => { console.log(data); }, err => { console.log(err); });
I'm unable to call method 2(POST Type Method) because instance created as GET type and I want to change it as per my API method type
Please help me with this..