fix: Upgrade graphql and@apollo/client#11200
Conversation
| uri, | ||
| credentials, | ||
| headers, | ||
| link = uri ? new HttpLink({ uri, credentials, headers }) : undefined, | ||
| link, |
There was a problem hiding this comment.
link option is now required
There was a problem hiding this comment.
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.
| throw new ApolloError({ | ||
| graphQLErrors: [new GraphQLError('some error')], | ||
| }); |
There was a problem hiding this comment.
Apollo Client 4 removes the ApolloError class entirely.
https://www.apollographql.com/docs/react/migrating/apollo-client-4-migration#removal-of-apolloerror
There was a problem hiding this comment.
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/clientto^4.1.6andgraphqlto^16.13.2in 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.
| const { | ||
| cache = new InMemoryCache().restore({}), | ||
| uri, | ||
| credentials, | ||
| headers, | ||
| link = uri ? new HttpLink({ uri, credentials, headers }) : undefined, | ||
| link, | ||
| ...otherOptions | ||
| } = options; |
There was a problem hiding this comment.
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.
| throw new ApolloError({ | ||
| graphQLErrors: [new GraphQLError('some error')], | ||
| }); | ||
| throw new GraphQLError('some error'); |
There was a problem hiding this comment.
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.
| throw new GraphQLError('some error'); | |
| throw new ApolloError({ | |
| graphQLErrors: [new GraphQLError('some error')], | |
| }); |
| }`, | ||
| variables: { id: params.id }, | ||
| parseResponse: ({ data }: ApolloQueryResult<any>) => { | ||
| parseResponse: ({ data }: ObservableQuery.Result<any>) => { |
There was a problem hiding this comment.
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.
| _queryType: IntrospectionField | ||
| ) => | ||
| (response: ApolloQueryResult<any>) => { | ||
| (response: ObservableQuery.Result<any>) => { |
There was a problem hiding this comment.
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).
| `, | ||
| variables: params.data, | ||
| parseResponse: ({ data }: ApolloQueryResult<any>) => { | ||
| parseResponse: ({ data }: ObservableQuery.Result<any>) => { |
There was a problem hiding this comment.
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.
| "graphql": "^15.6.0 || ^16", | ||
| "ra-core": "^5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "graphql": "^15.6.0", | ||
| "graphql": "^16.13.2", |
There was a problem hiding this comment.
@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).
| } | ||
| }, | ||
| "resolutions": { | ||
| "ra-data-graphql/@apollo/client": "4.1.6", |
There was a problem hiding this comment.
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)
| uri, | ||
| credentials, | ||
| headers, | ||
| link = uri ? new HttpLink({ uri, credentials, headers }) : undefined, | ||
| link, |
There was a problem hiding this comment.
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.
Fixes #10971
Problem
@apollo/clientversion isn't up to dateSolution
Upgrade
graphqland@apollo/clientUsefull 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-demoAdditional Checks
masterfor a bugfix or a documentation fix, ornextfor 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