Globally cached introspected schema causes problems when using two or more data providers
What you were expecting: When using two data providers based on ra-data-graphql and combined with combineDataProviders, would like to be able to switch between the data providers correctly.
What happened instead: In react-admin/packages/ra-data-graphql/src/introspection.ts on line 12, a global introspectionPromise is defined. This is then used to return a cached version of the introspection upon calls to introspectSchema on line 18 in the same file. This works if there is only one data provider using the ra-data-graphql library as a base, but if there are two or more, then what happens is that the schema for a cached and wrong data provider is returned if a demand is made for data from a different data provider to the one that served up the original introspected schema that was cached.
Steps to reproduce:
- Create two data providers both based on the ra-data-graphql library,
- combine them with combineDataProviders
- Create two screens each showing one entity from each data provider
- Display the first screen
- Switch to second screen. Get an error because the schema doesn't match, which is because a cache of the previous schema was returned instead of the correct schema.
Related code: A very hacky workaround is to comment out the code that returns the cached introspected schema in the introspectSchema call, like so:
export const introspectSchema = async (
client: ApolloClient
This causes the introspection query to be run every time though.
- Preferably, a CodeSandbox forked from
- https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple (v4)
- https://codesandbox.io/s/github/marmelab/react-admin/tree/3.x/examples/simple (v3)
- A link to a GitHub repo with the minimal codebase to reproduce the issue
insert short code snippets here
Other information:
Environment
- React-admin version:
- 4.2.7
- Last version that did not exhibit the issue (if applicable):
- n/a
- React version:
- Browser:
- Not browser specific
- Stack trace (in case of a JS error):
Your use case is too complex to just give it a try, Could you provide a codeSandbox or a repo with a simple project to reproduce the bug you are describing?
Thanks!
No news for some time, closing.