metropolitan-bronze
metropolitan-bronze•16mo ago

Automated Inferencer Setup

Hello Refine Community! I have a simple but sophisticated question about the inferencer (we're using AntdInferencer if that matters). Is there a way to automatically generate components (maybe from the CLI) based on pre-defined resources? I need to create 220 models in my case and that's around a thousand clicks :D. I don't have much hope, any hint is highly appreciated!
5 Replies
kapa.ai
kapa.ai•16mo ago
Hi @bastianwegge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hello! The @refinedev/inferencer package provides a way to automatically generate views for your resources based on the data structure. In your case, you can use the <AntdInferencer/> component from @refinedev/inferencer/antd to generate CRUD pages based on your API response with Ant Design components source (https://refine.dev/docs/tutorial/getting-started/antd/generate-crud-pages). To use the <AntdInferencer/> component, you need to pass appropriate values to the resources prop of the <Refine/> component in App.tsx source (https://refine.dev/docs/tutorial/getting-started/antd/generate-crud-pages). Here's an example of how to use the <AntdInferencer/> component:
import { Refine } from "@refinedev/core";
import { AntdInferencer } from "@refinedev/inferencer/antd";
import dataProvider from "@refinedev/simple-rest";

const App = () => {
return (
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
resources={[
{
name: "resource_name",
list: "/resource/list",
show: "/resource/show/:id",
create: "/resource/create",
edit: "/resource/edit/:id",
},
// Add more resources here
]}
>
<AntdInferencer />
</Refine>
);
};
export default App;
import { Refine } from "@refinedev/core";
import { AntdInferencer } from "@refinedev/inferencer/antd";
import dataProvider from "@refinedev/simple-rest";

const App = () => {
return (
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
resources={[
{
name: "resource_name",
list: "/resource/list",
show: "/resource/show/:id",
create: "/resource/create",
edit: "/resource/edit/:id",
},
// Add more resources here
]}
>
<AntdInferencer />
</Refine>
);
};
export default App;
However, the inferencer components are meant to be used in development environments and not in production environments source (https://refine.dev/docs/packages/documentation/inferencer). Unfortunately, there isn't a CLI command to automatically generate components based on pre-defined resources. You'll need to manually define the resources in the resources prop as shown in the example above. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai•16mo ago
<@317433576721219584> kapa.ai is still learning and improving, please let us how it did by reacting below
extended-salmon
extended-salmon•16mo ago
You can use this https://refine.dev/docs/packages/documentation/cli/#create-resource if it's not meet your needs, please never hesitate to give feedback to us 🤞
CLI | refine
refine CLI is a command line application that allows you to interact with your refine project and perform some tasks. This includes creating a new resource, managing updates, swizzle components, and runs your project (build, start, dev).
metropolitan-bronze
metropolitan-bronze•16mo ago
Thank you very much @alicanerdurmaz !
unwilling-turquoise
unwilling-turquoise•8mo ago
Just in case this is helpful to anyone: CLI generation of Inferencer folder and files have been moved to the add resource function. https://refine.dev/docs/packages/cli/#resource
refine add resource your-resource-name-here
To make an additional request for future CLI improvements. Can a switch be added to inject the code that is auto-generated by the Inferencer feature into each file? Creation of these long forms is a massive time save.
CLI | refine
Refine CLI is a command line application that allows you to interact with your Refine project and perform some tasks. This includes creating a new resource, managing updates, swizzle components, and runs your project (build, start, dev).