Skip to content
This repository was archived by the owner on Apr 14, 2023. It is now read-only.
This repository was archived by the owner on Apr 14, 2023. It is now read-only.

Client - Only absolute URLs are supported #1282

Description

@knuspertante

Hi,

I'am trying build an graphql-client with apollo for SSR and Client.

Server side works perfectly but when I hit the refresh button in my browser apollo throws an error.

I found a lot about this topic but nothing helps me ;-)

Only absolute URLs are supported

Ok I unterstand this, but in my opinion I put an absolute URL to HttpLink...

import fetch from "node-fetch";
import { ApolloClient } from "apollo-boost";
import { InMemoryCache } from "apollo-cache-inmemory";
import { HttpLink } from "apollo-link-http";

let GRAPHQL_URI;
if (typeof location !== "undefined") {
//this should be build an absolute url on client side....
    GRAPHQL_URI = location.protocol + "//" + location.hostname + ":" + location.port + "/graphql";
    console.log("Browser: GRAPHQL_URI: " + GRAPHQL_URI);
} else {
    GRAPHQL_URI = "/graphql";

    console.log("Server: GRAPHQL_URI: " + GRAPHQL_URI);
}
console.log("Init ApolloClient " + GRAPHQL_URI);


const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
        uri: GRAPHQL_URI,
        fetch
    })
});

export default client;

Output in browser console: Browser: GRAPHQL_URI: http://localhost:3000/graphql

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions