GET query missing: Apollo Client on nodejs server

Viewed 83

I'm running an Apollo GraphQL Client on a nodejs server locally that interacts with a GraphQL endpoint hosted on the cloud. I'm getting a "GET query missing" error whenever I query that endpoint with the client, despite the fact that I also have an Angular application using Apollo Angular (which internally uses Apollo Client), which is able to successfully query the cloud endpoint. The client also works fine if I host the GraphQL endpoint locally on my machine. I'm also using the cross-fetch package as my polyfill for fetch.

Here's my code for making the GraphQL client:

  public rebuildClient() {
    if (this.apollo) {
      this.apollo.stop();
      this.apollo.clearStore();
    }
    this.apollo = new ApolloClient(this.configureApolloClientOptions());
  }

  private configureApolloClientOptions() {
    const uploadLink = createUploadLink({
      uri: this.serverConfig.httpsPrefix + this.serverConfig.backendDomain + this.serverConfig.graphqlRelativePath,
      headers: { 'Apollo-Require-Preflight': 'true' },
      fetch: fetch,
    });

    if (this.graphQLWsClient) this.graphQLWsClient.dispose();
    this.graphQLWsClient = createClient({
      url: this.serverConfig.wssPrefix + this.serverConfig.backendDomain + this.serverConfig.graphqlRelativePath,
      connectionParams: {
        authentication: `Basic-Root ${this.authConfig.backendRootUser.username}:${this.authConfig.backendRootUser.password}`,
      },
      webSocketImpl: WebSocket,
    });

    const webSocketLink = new GraphQLWsLink(this.graphQLWsClient);

    // using the ability to split links, you can send data to each link
    // depending on what kind of operation is being sent
    const splitLink = split(
      // split based on operation type
      ({ query }) => {
        const definition = getMainDefinition(query);
        return definition.kind === 'OperationDefinition' && definition.operation === 'subscription';
      },
      webSocketLink,
      uploadLink,
    );

    return {
      link: splitLink,
      cache: new InMemoryCache(),
    };
  }

Here's a template for the serverConfig, which is a JSON file:

{
    "backendDomain": "localhost:3000",
    "cdnDomain": "localhost:3000",
    "cdnHttpsPrefix": "http://",
    "httpsPrefix": "http://",
    "wssPrefix": "ws://",
    "cdnRelativePath": "/cdn",
    "dynamicCdnRelativePath": "/cdn/dynamic",
    "graphqlRelativePath": "/graphql",
    "selfHostedPrefix": "cdn://",
    "archiveCategoryId": ""
}

Note that everything works if backendDomain is set to a localhost domain. But when I set it to an actual domain, the Apollo Client breaks with the errors mentioned above.

0 Answers
Related