Reputation: 1150
We have a docker image that sets up the backend server and the frontend NextJS application that is using ApolloClient. During the build process of the NextJS application the Apollo client tries to query the backend server'd graphql endpoint which is not working because the server has not been started.
Is there any way to have the ApolloClient NOT query outside servers during build time? Here's the constructor:
function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === 'undefined',
link: createUploadLink({
uri: process.env.HOSTNAME + '/graphql',
credentials: 'same-origin',
}),
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
allPosts: concatPagination(),
},
},
},
}),
onError: ({ networkError, graphQLErrors }) => {
console.log('graphQLErrors', graphQLErrors)
console.log('networkError', networkError)
}
})
}
Ultimately what we want to have is one docker container running the backend (Java) server that serves the NextJS built static files.
Upvotes: 1
Views: 491
Reputation: 908
It's unclear from your question, but when do you want your query to be run?
typeof(window) !== 'undefined'
and use fetch + async/await.Upvotes: 1