apollographql / apollographql/apollo-client-integrations

Upgrading to 0.11 doesn't trigger ApolloLink properly

Open
#348 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
556
Forks
53
PR merge metrics
No merged PRs in 30d

Description

We're attempting to upgrade `@apollo/experimental-nextjs-app-support` and running into issues. It appears we can upgrade `@apollo/client` to 3.11.4 without any problems, and upgrading `@apollo/experimental-nextjs-app-support` to 0.10.1 still works. But, upgrading to 0.11.x is resulting in a custom ApolloLink from running properly.

We are using `apollo-link-scalars` to transform specific graphql fields before they get cached in the apollo client.
https://github.com/eturino/apollo-link-scalars

Example:

```
export const TYPES_MAP: FunctionsMap = {
ISO8601Date: {
serialize: (parsed: unknown): string => {
if (parsed instanceof Date) {
return formatISO(parsed, { representation: "date" });
}
throw new GraphQLError(`Cannot serialize into ISO date: ${parsed}`);
},
parseValue: (raw: unknown): Date | null | undefined => {
if (raw === null || raw === undefined) return raw;
if (typeof raw === "string") {
return parseISO(raw);
}
throw new GraphQLError(`Cannot parse ISO date: ${raw}`);
},
},
};

const scalarsLink = withScalars({ schema: buildSchema(SCHEMA), typesMap: TYPES_MAP });

return new NextSSRApolloClient({
cache: new NextSSRInMemoryCache({ ... }),
link: ApolloLink.from([scalarsLink, httpLink]),
});
```

Before version 0.11, SSR would convert a string date (e.g. "2024-08-19") into a JavaScript Date object, and then the result would be serialized for the client. Then the client would read the query from the cache and have the JavaScript Date object available in the data returned.

However, after upgrading to 0.11, SSR still converts the string date into a JavaScript Date object and serializes the query results as it always has, but after the client hydrates, the date is not converted back to a Date object and only exists as a string (e.g. "2024-08-19T00:00:00Z") from the SSR serialization.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the shown NextSSRApolloClient setup with ApolloLink.from, withScalars, NextSSRInMemoryCache, and the httpLink while comparing versions 0.10.1 and 0.11.x. Trace SSR serialization and client hydration, then verify that the cached ISO8601Date value is converted back to a JavaScript Date after hydration.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, next.js, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.