Steams / ra-data-hasura-graphql

React-admin data provider for Hasura GraphQL endpoints
MIT License
211 stars 33 forks source link

Enable easier override of queries #68

Closed cpv123 closed 3 years ago

cpv123 commented 3 years ago

Description

The main aim of the PR is to allow developers to more easily extend/customise the GraphQL query fields sent from their React Admin app to Hasura backend.

Why?

Currently it is very difficult to extend/customise queries - the fields must be defined with graphql-ast-types-browser syntax (very verbose) and the developer has to import many functions from this package: https://github.com/Steams/ra-data-hasura-graphql#example-query-related-entities

How does this PR make it easier to extend/customise queries?

  1. It shows developers (in the README) how to define their extended or custom queries using familiar gql template literals
  2. It reduces the complexity of extending/customising queries - it greatly reduces the number of imports and number of steps needed to do so

This should resolve the following issues: https://github.com/Steams/ra-data-hasura-graphql/issues/38, https://github.com/Steams/ra-data-hasura-graphql/issues/66, https://github.com/Steams/ra-data-hasura-graphql/issues/29

Is it backwards compatible?

Yes.

This change introduces additional arguments to this library's default export - the buildDataProvider function - if these arguments are not provided then all defaults are used.

For developers that are already providing a buildQuery override following https://github.com/Steams/ra-data-hasura-graphql#example-query-related-entities then their overrides will remain unchanged. This is possible because of 24b4a96 (#68)

How to review this PR

Because I ran prettier over the entire project, it looks as though lots of files have changed, but actually only a few have. Review the first 3 commits along with the final commit to see that actual changes that have been made.

  1. 8b14196 (#68)
  2. aa015ed (#68)
  3. 2657081 (#68)
  4. a98fb7f (#68) (README update)

Proving this approach

cpv123 commented 3 years ago

@Steams can you take a look at this PR - I think it will help out a lot of people using this library. Also @datakurre I think you might be interested.