I got a Error: Http failure response for http://localhost:10600/playground/: 404 Not Found at new ApolloError

Viewed 434

I am working with graphQL. I am trying to make a request. The server has authorization. I took an example from the official site and changed the uri to http://localhost:10600/playground/. But the error 404 occurs constantly. Although the service itself is available at this address.

My graphql.module.ts

import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { Apollo, APOLLO_OPTIONS } from 'apollo-angular';
import { HttpLink } from 'apollo-angular/http';
import { InMemoryCache, ApolloLink } from '@apollo/client/core';
import { setContext } from '@apollo/client/link/context';

const uri = 'http://localhost:10600/playground/';

export function createApollo(httpLink: HttpLink) {
  const basic = setContext((operation, context) => ({
    headers: {
      Accept: 'charset=utf-8'
    }
  }));

  const auth = setContext((operation, context) => {
    const token = localStorage.getItem('access_token');
    console.log(token)
    if (token === null) {
      return {};
    } else {
      return {
        headers: {
          Authorization: `Bearer ${token}`
        }
      };
    }
  });

  const link = ApolloLink.from([basic, auth, httpLink.create({ uri })]);
  const cache = new InMemoryCache();
  console.log(link);
  return {
    link,
    cache
  };
}

@NgModule({
  exports: [
    HttpClientModule,
  ],
  providers: [{
    provide: APOLLO_OPTIONS,
    useFactory: createApollo,
    deps: [HttpLink]
  }]
})
export class GraphQLModule { }

enter image description here

Token is valid. Client side is http://localhost:4200/

1 Answers

I had the same error message for 2 different errors.

  1. My URL was wrong, i provide https://server-name.domain but actually it was https://server-name.domain/graphql

In your case try to remove /playground 2. I had a typo in my query

Check your network tab in chrome and read the server response, was more helpful than console.log Http failure response

Related