ugly-tan
ugly-tan2y ago

Custom Graphql query inputs

Hello, Can someone please explain to me how to write custom Graphql queries? We are using the Pothos library that autogenerates all of the CRUD resolvers. I would like to use those queries for some basic create, update, and listings in the table. I understand that @pankod/refine-graphql is not doing schema introspection and it is creating its own inputs For a basic query { barbers { id, name } } It is creating query ($sort: String, $where: JSON) { barbers (sort: $sort, where: $where) { id, name } } I've tried to create my own query using gql-query-builder and set it to useTable metaData, but dataProvider is still adding* $sort: String, $where: JSON* My question is, is it possible to use default dataProvider by just sending custom queries, or do I need to create a new dataProvider that will need to handle all the use cases of various queries/mutations and create a query for it inside that dataProvider? There is no documentation for custom queries. I've found a couple of the same questions and didn't understand what was the solution to this. https://discord.com/channels/837692625737613362/890159787621355521/979168892125581342 https://discord.com/channels/837692625737613362/890159787621355521/993207528575995984 My barbers query looks like this: Query barbers ( cursor BarberWhereUniqueInput, distinct [BarberScalarFieldEnum!], orderBy [BarberOrderByWithRelationInput!], skip Int, take Int, where BarberWhereInput ) [Barber!]! And his where input like this: BarberWhereInput FIELDS AND [BarberWhereInput!] appointments AppointmentListRelationFilter barberServices BarberServiceListRelationFilter barberWorkTimeOverrides BarberWorkTimeOverrideListRelationFilter barberWorkTimes BarberWorkTimeListRelationFilter id StringFilter name StringFilter NOT [BarberWhereInput!] OR [BarberWhereInput!] password StringFilter timeSlots TimeSlotListRelationFilter type EnumBarberTypeFilter username StringFilter
No description
No description
No description
6 Replies
Omer
Omer2y ago
Hi @zgajo 👋, You can override spesific functions of dataProvider according to your API requirements ⚡️ https://refine.dev/docs/faq/#how-i-can-override-specific-function-of-data-providers Or you can send raw graphql queries with metaData
FAQ | refine
How can I change the form data before submitting it to the API?
ugly-tan
ugly-tan2y ago
Ok, so I need to override getList function, and handle adding where field and its input operations name, if filters is sent into getList function? And this needs to be handled for each getList query resource and depending on it create gql query? Isn't it easier to use introspection for this. React-admin is using introspection and I've just little addapted their Prisma graphql data profider for my use case, and that worked like a charm
Omer
Omer2y ago
I think you can handle this in dataProvider. Have you checked our hasura data provider? https://github.com/refinedev/refine/blob/next/packages/hasura/src/dataProvider/index.ts#L208
GitHub
refine/index.ts at next · refinedev/refine
Build your React-based CRUD applications, without constraints. - refine/index.ts at next · refinedev/refine
ugly-tan
ugly-tan2y ago
Thanks for your reply @Omer
Omer
Omer2y ago
both have pros and cons, but we are working on a new data provider approach 🚀
ugly-tan
ugly-tan2y ago
ok, thanks... I'll give it a try tomorrow and see where I get with it