Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass down custom graphql query via Edit, Show, Create Component #7357

Closed
DVGY opened this issue Mar 7, 2022 · 4 comments
Closed

Pass down custom graphql query via Edit, Show, Create Component #7357

DVGY opened this issue Mar 7, 2022 · 4 comments
Assignees

Comments

@DVGY
Copy link

DVGY commented Mar 7, 2022

React admin is a great library. We have built a large app out of it

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

We are changing our app from REST to GraphQL. We have lots of custom views, and approx. 100 REST API resources. A view (Front end UI) maybe shown differently to each person depending on some logic.

While moving from REST to GraphQL, we found two problems,

  1. We did not find any props to pass custom GraphQL Query or Mutation down to the DataProvider for Edit, Create and Show Component.
  2. In the ra-simple-graphql it is advised to use resource and type of DataProvider to handle custom queries. If we use this approach then we may need to write Number of resources x Number of DataProvider Methods, If/else Conditions.
    (100 * 6 = 600) in my case.

There for we were hoping that we could call custom GraphQL Query which will be passed down via Edit or Show Component. Then we may need not write to 600 Conditions, It will be much less i.e only 6 conditions or 10 conditions.
image

For example


const customGQLQuery = gql`

query User{
  User {
   id,
   address
   }

`

<Edit customGQLQuery = {customGQLQuery}>
<Edit />


const getOne = async (resource,params) => {

if(params.customGQLQuery){
  // execute custom gql Query

}
else {
 // use default query builder

}

Since we could not find any ways to pass props down to DataProvider, we have to write lot of code otherwise graphql will call it's default query and bring fields we may not need for the UI

Describe the solution you'd like
A clear and concise description of what you want to happen.

Ability to pass custom prop via for custom GraphQL Query, and

Describe alternatives you've considered
For List component I have used filters to pass custom graphql query.

Additional context
Add any other context or screenshots about the feature request here.

It is also possible that I have missed something and my problems solution is already available. In that case pls point out to me specific resource

@fzaninotto
Copy link
Member

React-admin v4 introduces the meta parameter on all dataProvider queries, so what you ask is already possible by using the dataProvider hooks (e.g. useGetOne) manually.

We'll add support for passing a custom meta parameter to view components (e.g. <Edit>) in a future minor release.

@DVGY
Copy link
Author

DVGY commented Mar 8, 2022

@fzaninotto Thank you so much. I will be waiting eagerly for this.

@panfiva
Copy link

panfiva commented May 27, 2022

@fzaninotto, do you have estimated timeline for including support for passing custom meta to view components? Thanks

@fzaninotto
Copy link
Member

Fixed by #7841

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants