Skip to content

fix: Upgrade graphql and@apollo/client#11200

Open
erwanMarmelab wants to merge 3 commits intomasterfrom
upgrade-graphql-and-apollo/client
Open

fix: Upgrade graphql and@apollo/client#11200
erwanMarmelab wants to merge 3 commits intomasterfrom
upgrade-graphql-and-apollo/client

Conversation

@erwanMarmelab
Copy link
Contributor

@erwanMarmelab erwanMarmelab commented Mar 25, 2026

Fixes #10971

Problem

@apollo/client version isn't up to date

Solution

Upgrade graphql and@apollo/client

Usefull links

https://github.com/apollographql/apollo-client/blob/main/CHANGELOG.md#breaking-changes-summary

https://www.apollographql.com/docs/react/migrating/apollo-client-4-migration

https://github.com/graphql/graphql-js/releases/tag/v16.0.0

How To Test

make install && make build && make run-graphql-demo

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • [ ] The PR includes unit tests (if not possible, describe why)
  • [ ] The PR includes one or several stories (if not possible, describe why)
  • [ ] The documentation is up to date

Comment on lines -17 to +18
uri,
credentials,
headers,
link = uri ? new HttpLink({ uri, credentials, headers }) : undefined,
link,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link option is now required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep uri, credentials and headers. keep the default for link. And update the type so that we require either link, or uri, credentials and headers to construct link.

Comment on lines -13 to -15
throw new ApolloError({
graphQLErrors: [new GraphQLError('some error')],
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrades the GraphQL/Apollo client stack across the monorepo (library packages + demo) to newer major versions, and adjusts TypeScript usage to match the updated Apollo APIs.

Changes:

  • Bump @apollo/client to ^4.1.6 and graphql to ^16.13.2 in relevant workspaces (and lockfile).
  • Update some Apollo-related TypeScript types/usages in ra-data-graphql, ra-data-graphql-simple, and the GraphQL demo.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
yarn.lock Locks updated dependency graph for Apollo v4 + GraphQL v16.
packages/ra-data-graphql/src/introspection.ts Adjusts ApolloClient typing in schema introspection helpers.
packages/ra-data-graphql/src/index.test.ts Updates error test setup for Apollo v4 (currently inconsistent with assertions).
packages/ra-data-graphql/src/buildApolloClient.ts Refactors client creation for Apollo v4 (currently breaks uri-based config).
packages/ra-data-graphql/package.json Upgrades Apollo/GraphQL versions (peer deps need alignment with Apollo v4).
packages/ra-data-graphql-simple/src/getResponseParser.ts Changes response typing (currently mismatched vs actual query()/mutate() results).
packages/ra-data-graphql-simple/package.json Upgrades Apollo/GraphQL versions (peer deps need alignment with Apollo v4).
examples/demo/src/dataProvider/graphql.ts Updates demo parseResponse typings (currently mismatched vs actual runtime results).
examples/demo/package.json Upgrades Apollo/GraphQL versions for the demo (missing required Apollo peer rxjs).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to 20
const {
cache = new InMemoryCache().restore({}),
uri,
credentials,
headers,
link = uri ? new HttpLink({ uri, credentials, headers }) : undefined,
link,
...otherOptions
} = options;
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildApolloClient no longer derives an HttpLink from uri/credentials/headers. Callers (e.g. the demo via clientOptions.uri) will now pass link: undefined and ApolloClient will throw at runtime because link is required. Consider restoring the previous behavior (create new HttpLink({ uri, credentials, headers }) when link isn’t provided) or update all call sites to pass an explicit link instead of uri.

Copilot uses AI. Check for mistakes.
throw new ApolloError({
graphQLErrors: [new GraphQLError('some error')],
});
throw new GraphQLError('some error');
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test still asserts error.body.graphQLErrors, but the mock now throws a raw GraphQLError, so handleError will wrap that and error.body won’t have graphQLErrors. To keep the test meaningful, throw an ApolloError (or an object shaped like it) with graphQLErrors: [new GraphQLError(...)], or update the assertions to match the new error shape.

Suggested change
throw new GraphQLError('some error');
throw new ApolloError({
graphQLErrors: [new GraphQLError('some error')],
});

Copilot uses AI. Check for mistakes.
}`,
variables: { id: params.id },
parseResponse: ({ data }: ApolloQueryResult<any>) => {
parseResponse: ({ data }: ObservableQuery.Result<any>) => {
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file switches from ApolloQueryResult to ObservableQuery.Result, but parseResponse here is called with the result of client.query()/client.mutate() (via ra-data-graphql), not a watchQuery result. Keeping the parameter typed as ApolloQueryResult (or a correct union type) will better reflect the actual runtime shape and avoid confusing consumers.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +18
_queryType: IntrospectionField
) =>
(response: ApolloQueryResult<any>) => {
(response: ObservableQuery.Result<any>) => {
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getResponseParser is used as the parseResponse handler for client.query()/client.mutate() results, which are ApolloQueryResult/mutation results—not ObservableQuery.Result (watchQuery). Using ObservableQuery.Result here is misleading and may break downstream typing; prefer ApolloQueryResult (and/or a union including mutation results if needed).

Copilot uses AI. Check for mistakes.
`,
variables: params.data,
parseResponse: ({ data }: ApolloQueryResult<any>) => {
parseResponse: ({ data }: ObservableQuery.Result<any>) => {
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above: parseResponse is typed as ObservableQuery.Result, but this handler receives the result of client.query()/client.mutate(), not watchQuery. Prefer ApolloQueryResult (or a correct union type) to match what ra-data-graphql passes at runtime.

Copilot uses AI. Check for mistakes.
Comment on lines 41 to +45
"graphql": "^15.6.0 || ^16",
"ra-core": "^5.0.0"
},
"devDependencies": {
"graphql": "^15.6.0",
"graphql": "^16.13.2",
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apollo/client@4.x declares graphql@^16 and rxjs@^7.3.0 as required peer dependencies. This package still advertises graphql: ^15.6.0 || ^16 and doesn’t declare rxjs, which can lead to peer resolution warnings/errors (especially under Yarn PnP) and an inaccurate compatibility signal to consumers. Consider updating peerDependencies to require graphql@^16 and adding rxjs (peer + devDependency as needed).

Copilot uses AI. Check for mistakes.
}
},
"resolutions": {
"ra-data-graphql/@apollo/client": "4.1.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be able to remove this line. We need to publish a new version of json-graphql-server (with the compatibility with apollo/client v4)

Copy link
Contributor

@ThieryMichel ThieryMichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ci is failing

Comment on lines -17 to +18
uri,
credentials,
headers,
link = uri ? new HttpLink({ uri, credentials, headers }) : undefined,
link,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep uri, credentials and headers. keep the default for link. And update the type so that we require either link, or uri, credentials and headers to construct link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

@apollo/client v4 and ra-data-graphql compatibility

3 participants