0

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()
    });
  }

}
  1. 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);
            });
      }
    
  2. 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..

VIVEK
  • 257
  • 1
  • 5
  • 18

1 Answers1

0

You want to make a Graphql query using get? Or only want to make a get request? in that case, you should use the httpclientmodule

Michael Chiche
  • 191
  • 1
  • 8