-
hi buddy, I want to build a custom query for a specify resource? I tried for days but couldn't find a solution…… Could you please give me some direction? Thank you very much! const AdminApp = () => {
const dataProvider = useDataProvider({
client: apolloClient,
aliasPrefix: "",
filters: {}, // custom filters
queryDialect: "nexus-prisma", // customize query dialect, defaults to nexus-prisma
});
if (!dataProvider) {
return <Loading />;
}
return (
<Admin dataProvider={dataProvider} authProvider={authProvider}>
<Resource name="Product" {...product} />
<Resource name="Customer" {...customer} />
<Resource name="Order" {...order} />
<Resource name="Activation" {...activation} />
<Resource name="ActivationWithCustomerProduct" {...activationWithCustomerProduct} />
</Admin>
);
}; |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 6 replies
-
i'll move that to discussion, hope that this is ok. |
Beta Was this translation helpful? Give feedback.
-
Not sure what you want to customize, but some hints: By default it will fetch all fields of a resource for list and detail view. You can customize which fields are fetched: https://github.com/panter/ra-data-prisma/blob/master/packages/dataprovider/README.md#customize-fetching--virtual-resources Additionaly, you can define custom filters for lists: https://github.com/panter/ra-data-prisma/blob/master/packages/dataprovider/README.md#custom-filters |
Beta Was this translation helpful? Give feedback.
-
I know it's possible to use 'ReferenceField' on the frontend 'connect' to create a new record, but now I want to use 'TextInput' for custom input, because I can see that the 'connectOrCreate' API is automatically generated by the backend and it works fine as shown above , it would be a shame if the frontend could not call the 'connectOrCreate' . I have seen some examples in But I really don't know how to do that in our Anyway, thank you very much for your reply. If it is really impossible, I have to give it up regretfully. |
Beta Was this translation helpful? Give feedback.
-
I can see 'connectOrCreate' in your source code, but I studied it for a long time and didn't know how to modify it. Because my technology is not good enough, I may not be able to give good advice, or you can refer to the 'API' of other React Admin 'Dataproviders' , many thanks! |
Beta Was this translation helpful? Give feedback.
-
@winner106 i proposed a PR: #89 see the tests and / or the readme for how to use that. Would that solve your use case? |
Beta Was this translation helpful? Give feedback.
-
You're such an efficient master, that's great! I hope that this need is also helpful to others, my use code is as follows, for reference: const dataProvider = useDataProvider({
client: apolloClient,
aliasPrefix: "",
filters: {},
queryDialect: "nexus-prisma",
customizeInputData: {
Order: {
create: (data, params) => ({
...data,
customer: {
connectOrCreate: {
create: {
email: params.email,
},
where: {
email: params.email,
},
},
},
}),
},
}
}); OrderCreate Component const OrderCreate = (props) => (
<Create {...props}>
<SimpleForm>
<ReferenceInput label="Product Name" source="product" reference="Product">
<SelectInput optionText="name" />
</ReferenceInput>
<TextInput source="email"/>
<NumberInput source="permitUsers" label="permitUsers" initialValue={3} />
<DateInput source="orderDate" label="orderDate" initialValue={new Date()} />
</SimpleForm>
</Create>
); |
Beta Was this translation helpful? Give feedback.
@winner106 i proposed a PR: #89
see the tests and / or the readme for how to use that. Would that solve your use case?