react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Globally cached introspected schema causes problems when using two or more data providers

Open kazlibrowski opened this issue 3 years ago • 1 comments

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:

  1. Create two data providers both based on the ra-data-graphql library,
  2. combine them with combineDataProviders
  3. Create two screens each showing one entity from each data provider
  4. Display the first screen
  5. 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, options: IntrospectionOptions ) => { // if (introspectionPromise) { // return introspectionPromise; // } introspectionPromise = runSchemaIntrospection(client, options); return introspectionPromise; };

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):

kazlibrowski avatar Aug 25 '22 12:08 kazlibrowski

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!

WiXSL avatar Sep 01 '22 12:09 WiXSL

No news for some time, closing.

slax57 avatar Dec 08 '22 11:12 slax57