You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apps with multiple graphql data providers (e.g. combined with combineDataProviders) would be able to query different GraphQL servers without error.
What happened instead:
The first graphql dataprovider that runs caches its introspection query results globally. Other dataproviders check that same introspection query and fail.
Steps to reproduce:
Imagine the following setup: an app that combines two data providers, for API A and B:
import{combineDataProviders}from'react-admin'importbuildGraphQLProviderfrom'ra-data-graphql-simple'exportconstApp=()=>{constclientA=newApolloClient({uri: '/api-A'})constclientB=newApolloClient({uri: '/api-B'})const[providerA,setProviderA]=useState<DataProvider>()const[providerB,setProviderB]=useState<DataProvider>()useEffect(()=>{buildGraphQLProvider({client: clientA}).then((provider)=>setProviderA(provider))},[clientA])useEffect(()=>{buildGraphQLProvider({client: clientB}).then((provider)=>setProviderB(provider))},[clientB])if(!providerA||!providerB)return<div>Loading...</div>constdataProvider=combineDataProviders((resource)=>{switch(resource){case'resourceA': returnproviderAcase'resourceB': returnproviderBdefault: thrownewError(`No data provider for ${resource}`)}})return(<AdmindataProvider={dataProvider}><Resourcename='resourceA'list={ResourceAList}/><Resourcename='resourceB'list={ResourceBList}/></Admin>)}
Navigate to /resourceA
a. Behind the scenes, ra-data-graphql runs an introspection query for A’s graphql server.
b. resourceA is queried and presented.
Navigate to /resourceB
a. Behind the scenes, ra-data-graphql uses the cached introspection query for A, even though we need introspection for B.
Result:
resourceB is not queried, and instead an error is thrown:
Error: Unknown resource resourceB. Make sure it has been declared on your server side schema.
Known resources are resourceA
Other information:
I believe the source of the problem is that ra-data-graphql/src/introspection.ts is built as a singleton, caching the introspection query promise with a let variable within the node module, regardless of different client or options arguments:
What you were expecting:
Apps with multiple graphql data providers (e.g. combined with combineDataProviders) would be able to query different GraphQL servers without error.
What happened instead:
The first graphql dataprovider that runs caches its introspection query results globally. Other dataproviders check that same introspection query and fail.
Steps to reproduce:
Imagine the following setup: an app that combines two data providers, for API A and B:
/resourceA
a. Behind the scenes,
ra-data-graphql
runs an introspection query for A’s graphql server.b.
resourceA
is queried and presented./resourceB
a. Behind the scenes,
ra-data-graphql
uses the cached introspection query for A, even though we need introspection for B.Result:
resourceB
is not queried, and instead an error is thrown:Other information:
I believe the source of the problem is that
ra-data-graphql/src/introspection.ts
is built as a singleton, caching the introspection query promise with alet
variable within the node module, regardless of differentclient
oroptions
arguments:react-admin/packages/ra-data-graphql/src/introspection.ts
Line 12 in dd1a205
react-admin/packages/ra-data-graphql/src/introspection.ts
Lines 18 to 27 in dd1a205
A potential solution is for
introspection.ts
to memoize the promise depending onclient
andoptions
.Environment
Stack Trace
The text was updated successfully, but these errors were encountered: