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

[RFR] GraphQL providers enhancements #2257

Merged
merged 4 commits into from
Sep 3, 2018
Merged

[RFR] GraphQL providers enhancements #2257

merged 4 commits into from
Sep 3, 2018

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Aug 31, 2018

Following #2243

  • Deprecate the override option
  • Exports the buildQuery function in dialect packages
  • Document how to wrap buildQuery to override specific queries

@djhi djhi changed the title [WIP] GraphQL providers enhancements [RFR] GraphQL providers enhancements Aug 31, 2018
// in src/dataProvider.js
import buildGraphcoolProvider, { buildQuery } from 'ra-data-graphcool';

const overrideBuildQuery = buildQuery => (fetchType, resource, params) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the signature is wrong here: (buildQuery) => (introspectionResults) => (fetchType, resource, params).

Same goes for const builtQuery = buildQuery(introspectionResults)(fetchType, resource, params);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right !

Copy link
Collaborator Author

@djhi djhi Aug 31, 2018

Choose a reason for hiding this comment

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

It seems cumbersome to use it that way, isn't it? Lot of boilerplate again...

What do you think of the following usage:

// in src/dataProvider.js
import buildGraphcoolProvider from 'ra-data-graphcool';

const buildQuery = (fetchType, resource, params, defaultBuildQuery) => {
    const builtQuery = defaultBuildQuery(fetchType, resource, params);

    if (resource === 'Command' && fetchType === 'GET_ONE') {
        return {
            // Use the default query variables and parseResponse
            ...builtQuery,
            // Override the query
            query: gql`
                query Command($id: ID!) {
                    data: Command(id: $id) {
                        id
                        reference
                        customer {
                            id
                            firstName
                            lastName
                        }
                    }
                }`,
        };
    }

    return builtQuery;
}

export default buildGraphcoolProvider({ buildQuery })

The dataProvider would call your buildQuery with the default one it uses.

EDIT: edited for even simpler usage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually a bad idea as one may need the introspection results for advanced scenarios

if (resource === 'Command' && fetchType === 'GET_ONE') {
return {
// Use the default query variables and parseResponse
...buildQuery,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be builtQuery instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!

@djhi djhi changed the title [RFR] GraphQL providers enhancements [WIP] GraphQL providers enhancements Aug 31, 2018
@djhi djhi changed the title [WIP] GraphQL providers enhancements [RFR] GraphQL providers enhancements Sep 1, 2018
@djhi djhi changed the title [RFR] GraphQL providers enhancements [WIP] GraphQL providers enhancements Sep 1, 2018
@djhi djhi changed the title [WIP] GraphQL providers enhancements [RFR] GraphQL providers enhancements Sep 1, 2018
@@ -58,6 +58,12 @@ export default async options => {
...otherOptions
} = merge({}, defaultOptions, options);

if (override && process.env.NODE_ENV === 'production') {
Copy link
Member

Choose a reason for hiding this comment

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

I think we still use the override option in the dataProvider of the examples/graphcool-demo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed the demo

- [x] Deprecate the `override` option
- [x] Exports the `buildQuery` function in dialect packages
- [x] Document how to wrap it to override specific queries
@fzaninotto fzaninotto merged commit 63878c2 into next Sep 3, 2018
@fzaninotto fzaninotto deleted the graphql-enhancements branch September 3, 2018 12:27
@fzaninotto fzaninotto added this to the 2.3.0 milestone Sep 3, 2018
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.

3 participants