Closed EgidioCaprino closed 5 years ago
@lfades can you help me?
That's not expected, can you try disabling SSR and see if it still happens ?, and if possible, is your code open source ?
I've already tried to disable ssr
but still getting the same issue. My project is here https://github.com/EgidioCaprino/youvector/blob/master/website/pages/index.js#L30
Can you move the query out of the component and try again ? it should not be there btw
@lfades I've tried this but getting the same error as before
const query = gql`
query($id: ID!) {
getCategory(id: $id) {
name
description
subCategories {
name
illustrations {
id
name
}
}
parentCategory {
id
}
}
}
`;
export default withRouter(({ router }) => {
const { id } = router.query;
return (
<Query query={query} variables={{ id }}>
{({ loading, error, data }) => {
if (error) {
throw error;
}
if (loading) {
return <Spinner />;
}
const category = data.getCategory;
if (category.parentCategory && category.parentCategory.id) {
// @todo this redirect is not working probably because of this https://github.com/lfades/next-with-apollo/issues/45
Router.replace({
href: '/category',
query: { id: category.parentCategory.id },
}).catch(() => {});
}
return <CategoryPage {...category} />;
}}
</Query>
);
});
Btw, why should not the query
be defined inside a component?
because gql
will transform the query into an AST, it's not something to be done every render because it takes time, and it should be done once. If you do a console log of data
in the query response, do you see undefined
?
I've added this console.log
....
{({ loading, error, data }) => {
console.log('data', data);
....
On client side it logs this
While on server side it logs this
Thanks for the heads up with gql
. I'll look better into it :smiley:
Is that everything you are able to see ? I think that the issue may be with trying to do the request in the server with aws-appsync
, I don't think that it just works out of the box without any special configuration for SSR, can you go to their docs and confirm that ?
I was able to set it up correctly with next-apollo-appsync
but that didn't work out with new components such <Query>
and <Mutation>
and I would ended up using the old graphql
function. That's why I wanted to try your library, which I think it's pretty cool.
Unfortunately doesn't seem to bind very well with AppSync so I guess I should fall back on next-apollo-appsync
.
Well, this is what you're missing: https://github.com/dabit3/next-apollo-appsync/blob/master/src/initApollo.js#L16
I can make a example that works for you, let me finish my breakfast first
Thank you so much @lfades :heart:
This seems to have fixed the problem https://github.com/EgidioCaprino/youvector/commit/3e7a4b692059e013998e9131bfe186167ef3b4d4
Amazing, good work 👍 💃
Oh @EgidioCaprino btw you need to create the client inside the function, not outside, or you'll have a ton of problems because the client needs to be created always in SSR, and only be reused in the client.
Do I need to do so even if my backend runs on a Lambda function in AWS? That is stateless and the connection would not be shared anyway, right?
Yes, even so, don't take the chance of having a memory leak.
Alright, thanks @lfades :+1:
Hi all,
I'm getting this error when using
next-with-apollo
in this project here.I'm using the
Query
component rather than thegraphql
function.That error is server-side. Data is fetched correctly on client-side. Is that the expected behaviour?