Open knuspertante opened 4 years ago
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
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 ;-)
Ok I unterstand this, but in my opinion I put an absolute URL to HttpLink...
Output in browser console: Browser: GRAPHQL_URI: http://localhost:3000/graphql