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

TypeError: Cannot read property 'id' of null #96

Open
ilyas-shah opened this issue May 9, 2020 · 1 comment
Open

TypeError: Cannot read property 'id' of null #96

ilyas-shah opened this issue May 9, 2020 · 1 comment

Comments

@ilyas-shah
Copy link

Got an error when subscribing to new links.


updateQuery: (prev, { subscriptionData }) => {
        if (!subscriptionData.data) return prev;

        const newLink = subscriptionData.data.newLink;

        **const exists = prev.feed.links.find((link) => link.id === newLink.id);**

        if (exists) return prev;

        return Object.assign({}, prev, {
          feed: [newLink, ...prev.feed.links],
          count: prev.feed.links.length + 1,
          __typename: prev.feed.__typename,
        });
      },
    });

when the "linkList" page loads, the value of newLink is null. So rather than proceeding further, we return the prev/current list.


updateQuery: (prev, { subscriptionData }) => {


        if (!subscriptionData.data) return prev;

        const newLink = subscriptionData.data.newLink;

       **if (!newLink) return prev;**

        const exists = prev.feed.links.find((link) => link.id === newLink.id);

        if (exists) return prev;

        return Object.assign({}, prev, {
          feed: [newLink, ...prev.feed.links],
          count: prev.feed.links.length + 1,
          __typename: prev.feed.__typename,
        });
      },
    });

@ilyas-shah
Copy link
Author

I also found the updateQuery function is called 2 times when someone posts a link. First time with the prev data and second without prev data.

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

1 participant