ambitious-aqua
ambitious-aqua7mo ago

Refine Data Provider Query

Hi Amazing folks @ Refine - Had a question about Refine Data Providers. I have created "named" data providers for each resource in Refine. I also have one default data provider that according to me is unused. My resource array looks like below and my resources have relations. For ex: Clients belong to Companies. When we run the project, I can see some queries (through the browser network console) go to the "default" data provider even though every resource is using a "named" data provider. I am trying to understand why would any Refine Query goto the default data provider in this case. Any pointers or explanations for this behavior? We plan to use multiple data providers so this separation is important to use. It's probably not relevant but we are using Material UI in our project, FYI. Thanks for your help! [ { name: 'organizations', meta: { parent: 'json-server', dataProviderName: 'json_server', }, list: '/organizations', show: '/organizations/show/:id', edit: '/organizations/edit/:id', create: '/organizations/create', }, { name: 'companies', identifier: 'json-companies', meta: { parent: 'json-server', dataProviderName: 'json_server', }, list: '/companies', show: '/companies/show/:id', }, { name: 'clients', identifier: 'json-clients', meta: { parent: 'json-server', label: 'Clients', icon: <PeopleAltIcon />, dataProviderName: 'json_server', canDelete: true, }, list: '/clients', show: '/clients/show/:id', edit: '/clients/edit/:id', create: '/clients/create', }, { name: 'practitioner', meta: { parent: 'facility-portal', dataProviderName: 'copilot', }, list: '/practitioner', show: '/practitioner/show/:id', edit: '/practitioner/edit/:id', create: '/practitioner/create', }, ];
7 Replies
kapa.ai
kapa.ai7mo ago
Hi @pankaj_81531. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Refine, when you have multiple data providers, a default data provider is required. This is used as a fallback for resources that do not have a specific data provider assigned to them. Even if you have assigned a specific data provider to each resource, the default data provider might still be used in certain scenarios. One such scenario could be when dealing with relations between resources. For example, if a clients resource from json_server data provider has a relation with companies resource of default data provider, the default data provider might be used to handle requests related to this relation. To avoid this, you can define a companies resource in the resources array and pass json_server in options.dataProviderName. This way, the json_server data provider will be used to handle the requests for companies resource. Here is an example of how you can do this:
{
name: 'companies',
identifier: 'json-companies',
meta: {
parent: 'json-server',
dataProviderName: 'json_server',
},
options: {
dataProviderName: 'json_server',
},
list: '/companies',
show: '/companies/show/:id',
}
{
name: 'companies',
identifier: 'json-companies',
meta: {
parent: 'json-server',
dataProviderName: 'json_server',
},
options: {
dataProviderName: 'json_server',
},
list: '/companies',
show: '/companies/show/:id',
}
Please note that this is just a possible explanation based on the information provided in the extracts. If this doesn't solve your issue, it would be helpful to have more details about the specific queries that are going to the default data provider. For more information, you can refer to the Refine documentation on using multiple data providers (https://refine.dev/docs/api-reference/core/providers/data-provider/#using-multiple-data-providers) and the Github issue discussing the usage of multiple data providers (https://github.com/refinedev/refine/issues/3483). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@1148728588506501242> kapa.ai is still learning and improving, please let us know how it did by reacting below
ambitious-aqua
ambitious-aqua7mo ago
@kapa.ai - In my case, related resources (clients and companies) are using the same data provider. I understand that if the related resourcs have different data providers then default data provider can come into play. But if related resources have same data provider then it should not happen. Is that a valid understanding? Kindly see below two resources where my relations exist. You will notice that both of them use the same data provider "json_server". { name: 'companies', identifier: 'json-companies', meta: { parent: 'json-server', dataProviderName: 'json_server', }, list: '/companies', show: '/companies/show/:id', }, { name: 'clients', identifier: 'json-clients', meta: { parent: 'json-server', label: 'Clients', icon: <PeopleAltIcon />, dataProviderName: 'json_server', canDelete: true, },
kapa.ai
kapa.ai7mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, your understanding is correct. If related resources are using the same data provider, then all requests related to these resources should be handled by the specified data provider, and the default data provider should not come into play. In your case, both companies and clients resources are using the json_server data provider. Therefore, all requests related to these resources should be handled by the json_server data provider. If you're still seeing requests going to the default data provider, it might be due to some other factors. It would be helpful to have more details about the specific queries that are going to the default data provider. For more information, you can refer to the Refine documentation on using multiple data providers (https://refine.dev/docs/api-reference/core/providers/data-provider/#using-multiple-data-providers) and the Github issue discussing the usage of multiple data providers (https://github.com/refinedev/refine/issues/3483). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@1148728588506501242> kapa.ai is still learning and improving, please let us know how it did by reacting below
conscious-sapphire
conscious-sapphire7mo ago
Hello @pankaj_81531 you could explicitly pass dataProviderName to the resources as mentioned, do you still have this problem? Let us know, we'd like to help!
ambitious-aqua
ambitious-aqua6mo ago
Hi @batuhanw - Thanks for the offer to help. In the example that I was discussing, I am passing dataProviderName explicitly. See below where companies and clients resources have dataProviderName specified. I tried troubleshooting why default data provider was coming into play but could not really figure it out. It comes into play when I am trying to work with "clients" resource. Clients resource has a relationship with "companies" resource. That relationship reflects as a drop down of Companies on my clients resource UI. That makes sense. But in browser dev tools, there is a call going to default data source which is a problem. If my default data source is not "json_server" then the dropdown (containing Companies) does not render. It's blank. I have not been able to identify excatly which query is causing this. { name: 'companies', identifier: 'json-companies', meta: { parent: 'json-server', dataProviderName: 'json_server', }, list: '/companies', show: '/companies/show/:id', }, { name: 'clients', identifier: 'json-clients', meta: { parent: 'json-server', label: 'Clients', icon: <PeopleAltIcon />, dataProviderName: 'json_server', canDelete: true, },