Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDataFromTree not working (render to Loading...) #131

Open
MaxmaxmaximusGitHub opened this issue Apr 19, 2020 · 10 comments
Open

getDataFromTree not working (render to Loading...) #131

MaxmaxmaximusGitHub opened this issue Apr 19, 2020 · 10 comments

Comments

@MaxmaxmaximusGitHub
Copy link

MaxmaxmaximusGitHub commented Apr 19, 2020

_app.js:

this code render

Loading...

import withApollo from 'next-with-apollo';
import { ApolloProvider } from '@apollo/react-hooks';
import ApolloClient, { InMemoryCache } from 'apollo-boost';
import { getDataFromTree } from '@apollo/react-ssr'


const App = ({Component, pageProps, apollo}) => (
  <ApolloProvider client={ apollo }>
    <Component { ...pageProps } />
  </ApolloProvider>
);

export default withApollo(function ({initialState}) {

  return new ApolloClient({
    uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn',
    cache: new InMemoryCache().restore(initialState || {})
  });

}, {getDataFromTree})(App, {getDataFromTree});
@thaisonnguyenbt
Copy link

I changed to use 4.3.0 and it render in server side

With 5.0.0 and 5.0.1, page is rendered at client side with "Loading..."

@MaxmaxmaximusGitHub MaxmaxmaximusGitHub changed the title getDataFromTree not working getDataFromTree not working (render to Loading...) May 1, 2020
@vitaliemiron
Copy link

same issue, but 4.3.0 doesn't work with material ui (this bug - #60 )

@VladDubrovskis
Copy link

Had similar issue but managed to resolve/work around:
No initialState was set - this was when you install @apollo/react-ssr and @apollo/react-hooks above 3.1.3.

@vitaliemiron
Copy link

If you want to fix that you shoul import getDataFromTree
import { getDataFromTree } from '@apollo/react-ssr';

and pass it into withApollo
export default withApollo(({ initialState }) => { return new ApolloClient({ link: concat(authMiddleware, httpLink), cache: new InMemoryCache().restore(initialState || {}), }), getDataFromTree });

@eric-burel
Copy link

@VladDubrovskis can you please share a working package.json? I struggle to find the right combination

@VladDubrovskis
Copy link

@eric-burel better late than never 😂 Sorry have missed the notification:
dependencies:

"dependencies": {
    "@apollo/react-hooks": "3.1.3",
    "@apollo/react-ssr": "3.1.3",
    "@sentry/node": "^5.11.2",
    "apollo-boost": "0.4.7",
    "axios": "^0.19.0",
    "express": "^4.17.1",
    "graphql": "^14.6.0",
    "graphql-tag": "^2.10.3",
    "isomorphic-unfetch": "^3.0.0",
    "next": "^9.3.6",
    "next-compose-plugins": "^2.2.0",
    "next-cookies": "^2.0.3",
    "next-i18next": "^4.2.1",
    "next-with-apollo": "5.0.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-hook-form": "^5.7.2",
  },

@acha5066
Copy link

acha5066 commented Jul 6, 2020

I had the same issue. It seems like this can be caused by a number of things but it turned out that using the react-apollo library was conflicting with this library. Removing it allowed queries to be resolved on server side. Hope that helps someone!

@adithemighty
Copy link

Hi,
we had a similar issue where we would get Loading instead of the data. Our problem was that we have a custom _document.js file where we do Stylesheet related stuff. Long story short: the apolloState needs to be passed to the app in case you have a custom _document.js file.

@danielzlotnik
Copy link

We've had the same issue, consolidating all of our Apollo dependency hell onto @apollo/client (as described here), and using

import { getDataFromTree } from '@apollo/client/react/ssr';

Solved it for us.

@lakshyasharma14
Copy link

Hi, we had a similar issue where we would get Loading instead of the data. Our problem was that we have a custom _document.js file where we do Stylesheet related stuff. Long story short: the apolloState needs to be passed to the app in case you have a custom _document.js file.
@adiyathemighty Do you have any sample code for this, I am facing the same issue that AppTree is not showing the query and thus ApolloState is also null. So the client is not making any calls on the server side but doing it on client-side only.

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

No branches or pull requests

9 participants