Skip to content

Help plz on. Upgrading apollo client #12453

Open
@drmax24

Description

@drmax24

3.7.3 -> 3.8.10

I have this code:

export function useCreateTags() {
    const [createMutation] = useMutation(
        mutations.CREATE_STORY_TAG_MUTATION,
        {
            update: (cache, { data: { createStoryTag } }) => {
                cache.modify({
                    fields: {
                        storyTags( // <-----------------------------Story tags have a problem if I use apollo client 3.8.10
                            existing: GetStoryTagsResponseType["storyTags"],
                            { toReference }
                        ) {
                            return {
                                items: [
                                    ...existing.items,
                                    toReference(createStoryTag),
                                ],
                            };
                        },
                    },
                });
            },
        }
    );

    return {
        createMutation,
    };
}

it works fine with apollo client 3.7.3

but in 3.8.10 I have an error.
at this line
storyTags(

TS2322: Type
(existing: {
    items: StoryTagItem[];
}, {toReference}: ModifierDetails) => {
    items: (StoryTagItem | Reference | undefined)[];
}
is not assignable to type
Modifier<Reference | AsStoreObject<{
    items: (StoryTagItem | Reference | undefined)[];
}>>
Types of parameters existing and value are incompatible.
Type
Reference | AsStoreObject<{
    items: (StoryTagItem | Reference | undefined)[];
}>
is not assignable to type { items: StoryTagItem[]; }
Property items is missing in type Reference but required in type { items: StoryTagItem[]; }

Do I need to work with cach.modify differently now?..
Can you suggest something?...


You can also give me advice on toReference as I don't fully understand it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions