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

GraphQL Simple Data Provider Sparse Field Support #9392

Merged
merged 6 commits into from
Dec 4, 2023

Conversation

maxschridde1494
Copy link
Contributor

Sparse Field Support for Queries and Mutations

By default, most data provider requests return

  1. All of the resource's top level fields as defined in the GraphQL schema
  2. Association objects containing only the association's ID.

This feature enables sparse field support for all data provider requests. Sparse fields are passed through via the existing meta param. This can increase efficiency, optimize client performance, improve security and reduce over-fetching. Also, it allows for the request of nested association fields beyond just their ID. It is available for all dataprovider actions.

An example getOne request would look like:

dataProvider.getOne(
    'posts',
    { 
        id, 
        meta: { 
            sparseFields: [
                'id', 
                'title', 
                { 
                    comments: [
                        'description', 
                        { 
                            author : [
                                'name', 
                                'email'
                            ]
                        }
                    ]
                }
            ]
        }
    },
);

@slax57
Copy link
Contributor

slax57 commented Nov 9, 2023

Hi,
Thank you so much for submitting this contribution.
It's gonna take us some time to review, as it's a quite substantial PR, but we are definitely willing to have a look.
Thank you for your patience.

@adguernier adguernier self-requested a review November 13, 2023 14:57
Copy link
Contributor

@adguernier adguernier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review.
Great job 👍

packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
@maxschridde1494
Copy link
Contributor Author

@adguernier Thanks for your feedback. I went ahead and made the recommended changes and improved the processSparseFields function.

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Thanks :)

packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the eslint warnings :)

packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
packages/ra-data-graphql-simple/src/buildGqlQuery.ts Outdated Show resolved Hide resolved
@maxschridde1494
Copy link
Contributor Author

Ahh got it. Not sure how I missed those warnings. Changes pushed up :)

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the feature is nice, I'm a bit reluctant to merge it as ra-data-graphql-simple is merely an example implementation. Are you actually using this provider?

@maxschridde1494
Copy link
Contributor Author

Yes, here at Talysto we have used ra-data-graphql-simple as a provider for many projects.

Over the years, our team has identified a fullstack application framework, which we are calling Groovestack, that powers many of our scalable applications across various industries. The stack consists of PostgreSQL, Rails, GraphQL and React-Admin. To connect our GraphQL APIs with React-Admin, we found that the flexibility of the ra-data-graphql-simple interface and recommended patterns / schema were a great starting point. We have made enhancements, some of which we found to be general purpose and are offering to the community through the PRs we have opened recently (more to come).

Here is a quick example demo of an admin dash powered by Groovestack CORE Jobs.

IMAGE ALT TEXT

You can easily experiment with Groovestack and it's CORE modules by using our create-groovestack utility.

@djhi djhi merged commit 36ba735 into marmelab:next Dec 4, 2023
10 checks passed
@djhi djhi added this to the 5.0.0 milestone Dec 4, 2023
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

Successfully merging this pull request may close these issues.

None yet

4 participants