Closed yoneapp closed 7 years ago
Hi @yoneapp, you need to include __typename
as follows in the result you return from updateQuery
:
shops: {
__typename: previousResult.shops.__typename,
edges: [...previousResult.shops.edges, ...newEdges],
pageInfo,
},
Thank you for your advice 🙇
@helfer how can I include this __typename
more "automatically" when I writeQuery
for instance from a component (wrapped with withApollo
and graphql
in the HoC`?
I ask because in this example from your website or in this one on your blog it does not look like you need it, but I get the following error/warning when I do not add it:
Missing field __typename in { ... }
and it does not look like the apollo cache has been updated then. Or do I just have to add it and that's it ^^
@natterstefan , I've written a withCursorResult
myself, because all my cursor based queries have the same structure. I'm able to run a fetchMore-query
with someting like:
const withData = graphql(COMMENTS_QUERY, {
options: ({ blogId, pageSize }) => ({
variables: {
blogId,
cursor: {
sortBy: 'createdAt',
sortDir: 'ASC',
limit: pageSize,
}
},
}),
},
props: withCursorResult({ query: COMMENTS_QUERY }),
});
On the server side I have a createCursorResult
so that it's also easy to create cursors from mongo collections.
Unfortunately it's not really easy to share that code in a generic reusable way; as I use some specific libraries (partial.lenses
and ramda
), but if wished for, I can place it (as-is) online as a gist.
@natterstefan This confused me also :slightly_smiling_face: The difference is that in the examples you linked to, the data is being returned from GraphQL and thus already has __typename
defined on it. If you pass in your own custom data, you'll have to add __typename
yourself.
Intended outcome:
I wanted a warning not to be displayed.
Actual outcome:
A warning was displayed on the console.
How to reproduce the issue:
I used such a code.
Could you advise me on this issue?