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

Client - Only absolute URLs are supported #1282

Open
knuspertante opened this issue Jun 2, 2020 · 0 comments
Open

Client - Only absolute URLs are supported #1282

knuspertante opened this issue Jun 2, 2020 · 0 comments

Comments

@knuspertante
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant