Hello, everyone
I have some issue in apollo client with subscription
if I do mutation in server and i want to see in client it was duplicate
it this problem with apollo client? or am i miss something
i want my query and subscription is updating every any subscription come.
duplicate in the bottom
my apollo cache.ts
import { InMemoryCache } from "@apollo/client";
import { offsetLimitPagination } from "@apollo/client/utilities";
export const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
posts: offsetLimitPagination(),
comments: {
keyArgs: false,
merge(existing: [], incoming) {
return incoming;
},
},
},
},
},
});
index.ts indicate duplicate node
const GET_NEW_POST_SUBS = gql`
subscription postCreated {
postCreated {
id
content
createdAt
user {
avatarUrl
username
id
name
}
likes {
user {
avatarUrl
name
}
id
}
comments {
id
user {
avatarUrl
name
username
}
}
}
}
`;
const Post = () => {
const [fullyLoaded, setFullyLoaded] = useState<any>(false);
const { data, networkStatus, error, fetchMore, variables, subscribeToMore } =
usePostQuery({
variables: {
limit: 5,
offset: 0,
},
fetchPolicy: "network-only",
notifyOnNetworkStatusChange: true,
});
useEffect(() => {
subscribeToMore({
document: GET_NEW_POST_SUBS,
// not using use subscription with graphql codegen
updateQuery: (prev: any, { subscriptionData }: any) => {
if (!subscriptionData.data) return prev;
const newPost = subscriptionData.data.postCreated;
return {
posts: [...prev.posts, newPost],
};
},
});
console.log(posts?.length);
});
Please help…