optimistic-gold
optimistic-gold12mo ago

nestjs-query wrong graphql format

Im trying to use the MuiInferencer together with NestJS-Query the Format that is correct and generated by NestJS-Query is following query { players { pageInfo { hasNextPage hasPreviousPage startCursor endCursor } edges { node { id firstName lastName created } cursor } } } But the query that Refine generates looks like the following query { players { nodes { id, firstName }, totalCount } } Note that "nodes" does not exist
14 Replies
kapa.ai
kapa.ai12mo ago
Hi @justin99b. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Refine's Inferencer tool is designed to help 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. However, it might not always generate the exact query structure that your specific API or backend service expects. In your case, it seems like the query generated by Refine's Inferencer does not match the structure expected by your NestJS-Query GraphQL API. The Inferencer is generating a query with "nodes", but your API expects a different structure. Unfortunately, based on the information provided in the extracts, there's no direct way to customize the query generated by the Inferencer. The Inferencer is primarily used to generate sample codes for your views and infer the fields of the data provider's response. If the Inferencer doesn't generate the correct query, you might need to write those components and queries yourself. As one of the community members mentioned in the Discord thread, the Inferencer is meant to save you some time during development, but it might not always produce production-ready code. For more information about the Inferencer and how to use it, you can check out the official documentation (https://refine.dev/docs/api-reference/mui/components/inferencer/). For examples of how to use the NestJS-Query data provider with Refine, you can check out this example in the documentation (https://refine.dev/docs/examples/data-provider/nestjs-query/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai12mo ago
<@337253340121399296> kapa.ai is still learning and improving, please let us know how it did by reacting below
stormy-gold
stormy-gold12mo ago
It doesn’t support relay format. You can use offset pagination for your dtos
optimistic-gold
optimistic-gold12mo ago
I just followed the official NestJS-Query Documentation 😄 i dont even know what a relay format is Thats what my Dto looks like
@ObjectType('Player')
export class PlayerDto {
@IDField(() => ID)
id!: number;

@FilterableField()
firstName!: string;

@FilterableField()
lastName!: string;

@Field(() => GraphQLISODateTime)
created!: Date;
}
@ObjectType('Player')
export class PlayerDto {
@IDField(() => ID)
id!: number;

@FilterableField()
firstName!: string;

@FilterableField()
lastName!: string;

@Field(() => GraphQLISODateTime)
created!: Date;
}
The only thing i can imagine is the FIlterableField
stormy-gold
stormy-gold12mo ago
Check the place where you define ‘resolvers’ array. You can import ‘PaginationMode’ enum. It should have .offset option
optimistic-gold
optimistic-gold12mo ago
Ah perfect! Setting it to offset now contains nodes and i had to enable enableTotalCount The Query now executes inside the playground but Refine still thows an error Actually i think the requests fails
No description
optimistic-gold
optimistic-gold12mo ago
No description
No description
optimistic-gold
optimistic-gold12mo ago
No description
optimistic-gold
optimistic-gold12mo ago
... We all love CORS dont we 🙂 Thanks for your help it works now! @kapa.ai How can i use Inferencer to not only edit or show but also to delete a entry
kapa.ai
kapa.ai12mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The Inferencer tool in Refine is primarily used to generate CRUD (Create, Read, Update, Delete) pages based on your data model. However, it doesn't directly handle the deletion of entries. The deletion of entries is typically handled by the data provider you're using with Refine. To enable deletion of entries, you need to specify canDelete: true in the meta property of your resource when defining your resources in the <Refine /> component. Here's an example from the extracts:
<Refine
resources={[
{
name: "posts",
list: "/posts",
create: "/posts/create",
edit: "/posts/edit/:id",
show: "/posts/show/:id",
meta: {
canDelete: true,
},
},
]}
>
<Refine
resources={[
{
name: "posts",
list: "/posts",
create: "/posts/create",
edit: "/posts/edit/:id",
show: "/posts/show/:id",
meta: {
canDelete: true,
},
},
]}
>
In this example, the canDelete: true property enables the deletion of "posts" entries. When you navigate to the detail view of a post, you should see a delete button if your data provider supports the delete operation. Remember, the actual deletion operation is performed by your data provider, not the Inferencer. The Inferencer just generates the pages and UI elements based on your data model. For more information about how to use the Inferencer, you can check out the official documentation (https://refine.dev/docs/api-reference/core/components/inferencer/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai12mo ago
<@337253340121399296> kapa.ai is still learning and improving, please let us know how it did by reacting below
optimistic-gold
optimistic-gold12mo ago
It works now but there are some queries triggered when loading the page again with a wrong query Now it seems like the resource name is missing in the query
No description
stormy-gold
stormy-gold12mo ago
Hello @justin99b suggested way to use inferencer is to copy/paste the generated code you see in UI and fine tune yourself. It gives a good starter but may not work perfectly.
optimistic-gold
optimistic-gold12mo ago
Alright gonna tes that. Thanks alot for your help! Its really usefull to have the generated code