stormy-gold
stormy-gold11mo ago

Inferencer customize query

Hello! Can someone please tell me how I can customize the request in the Inferencer for graphql query, how can i specified variables like "where" or "sort"
No description
No description
No description
22 Replies
kapa.ai
kapa.ai11mo ago
Hi @cyy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In refine, you can customize the GraphQL query by using the meta property in the Inferencer component. The meta property allows you to define values for your resources and methods in a single prop, and it is used when generating the code and inferring the fields. Here's an example of how you can define the meta values in Inferencer components:
<AntdListInferencer
meta={{
[resourceNameOrIdentifier: string]: {
[methodName: "default" | "getList" | "getMany" | "getOne" | "update"]: Record<string, unknown>,
}
}}
/>
<AntdListInferencer
meta={{
[resourceNameOrIdentifier: string]: {
[methodName: "default" | "getList" | "getMany" | "getOne" | "update"]: Record<string, unknown>,
}
}}
/>
In this structure, default is the default meta value for all the methods. If a specific meta value for a method for a resource is not provided, the default value will be used. Here's an example usage:
<AntdListInferencer
meta={{
posts: {
getList: {
fields: [
"id",
"title",
"content",
"category_id",
"created_at",
],
},
},
categories: {
default: {
fields: ["id", "title"],
},
},
}}
/>
<AntdListInferencer
meta={{
posts: {
getList: {
fields: [
"id",
"title",
"content",
"category_id",
"created_at",
],
},
},
categories: {
default: {
fields: ["id", "title"],
},
},
}}
/>
In this example, the getList method for the posts resource will only fetch the fields id, title, content, category_id, and created_at. For the categories resource, the default method will fetch the fields id and title. For more complex queries like "where" or "sort", you might need to use the custom method in the data provider. This method allows you to handle requests with custom parameters like URL, CRUD methods, and configurations. You can find more information about the custom method in the refine documentation (https://refine.dev/docs/api-reference/core/providers/data-provider/). Please note that the actual implementation of the "where" or "sort" parameters will depend on your GraphQL server's API. For more information, you can check out the refine documentation on Inferencer (https://refine.dev/docs/packages/documentation/inferencer/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@710818953974251553> kapa.ai is still learning and improving, please let us know how it did by reacting below
stormy-gold
stormy-gold11mo ago
@kapa.ai
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @cyy, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist: Perhaps try again in 15mins?
stormy-gold
stormy-gold11mo ago
this means I can’t pass "filters" or "where" to the Inferencer as in a custom request through a dataProvider? @kapa.ai
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @cyy, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist: Perhaps try again in 15mins?
stormy-gold
stormy-gold11mo ago
@kapa.ai this means I can’t pass "filters" or "where" to the Inferencer as in a custom request through a dataProvider?
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Based on the provided extracts, the Inferencer in refine does not directly support passing "filters" or "where" clauses. The Inferencer is primarily used to generate sample codes for your views and infer the fields of the data provider's response. However, refine provides several hooks and methods that allow you to pass filter parameters to your data provider. For example, hooks like useList, useInfiniteList, useExport, useAutocomplete, and useSelect all accept a filters property that can be used to send filter query parameters to the API. Here's an example usage with useList:
useList({
filters: [
{
field: "title",
operator: "contains",
value: "Foo",
},
],
});
useList({
filters: [
{
field: "title",
operator: "contains",
value: "Foo",
},
],
});
In this example, the getList method from the dataProvider will be called with the provided filters. For more complex or custom requests, you can use the custom method from the dataProvider. This method is passed to the useCustom hook and can be used to send custom filter query parameters of the request.
useCustom({
config: {
filters: [
{
field: "title",
operator: "contains",
value: "Foo",
},
],
},
});
useCustom({
config: {
filters: [
{
field: "title",
operator: "contains",
value: "Foo",
},
],
},
});
In this example, the custom method from the dataProvider will be called with the provided filters. For more information, you can refer to the refine documentation (https://refine.dev/docs/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@710818953974251553> kapa.ai is still learning and improving, please let us know how it did by reacting below
metropolitan-bronze
metropolitan-bronze11mo ago
Hey @cyy Inferencer is a powerful tool in the refine ecosystem that helps developers quickly generate CRUD (create, read, update, delete) pages for their data model. It analyzes your data model based on the resource scheme and automatically creates the pages with the required forms and tables for CRUD operations. There is no direct filtering support. Put the generated code in the list file and save it. You can then filter and sort. https://refine.dev/docs/api-reference/antd/hooks/table/useTable/#initial-filter-and-sorter I would also suggest you review the permanent filter section. https://refine.dev/docs/api-reference/antd/hooks/table/useTable/#filterspermanent
stormy-gold
stormy-gold11mo ago
@yildirayunlu I'm just trying to figure out how to solve my problem because the Inferencer makes a request which doesn't suits to my api maybe I misunderstood the concept
No description
metropolitan-bronze
metropolitan-bronze11mo ago
Hi, if the inferencer is generating a wrong query, you should create a list page using the useTable hook.
stormy-gold
stormy-gold11mo ago
I have the same issue with all refine hooks Third day was spent on doc searching
metropolitan-bronze
metropolitan-bronze11mo ago
Hi, can you make a codesandbox to understand the problem clearly?
stormy-gold
stormy-gold11mo ago
I'm not sure I can make codesandbox because of nda
stormy-gold
stormy-gold11mo ago
my graphQL client and data provider
No description
No description
stormy-gold
stormy-gold11mo ago
then Inferencer makes such request
No description
stormy-gold
stormy-gold11mo ago
but i need to pass this variables instead "start", "limit" e.t.c.
No description
wise-white
wise-white11mo ago
Hi @cyy Inferencer doesn't provide you a complete solution, it's meant to save you some time during development, if inferencer doesn't get it right, you should write those compionents, queries yourself. Don't expect it to be produce production ready-code.
stormy-gold
stormy-gold11mo ago
@batuhanw Hi, but i have the same story with hooks (like useList)
wise-white
wise-white11mo ago
1. Data Provider | refine
The Data Provider unit is optional for the tutorial. You can directly skip to the next unit, Adding CRUD PagesAdding CRUD PagesAdding CRUD PagesAdding CRUD PagesAdding CRUD Pages, if desired
stormy-gold
stormy-gold11mo ago
I really didn't find it, what I need Thank you