-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Conversation
packages/ra-data-graphcool/README.md
Outdated
// in src/dataProvider.js | ||
import buildGraphcoolProvider, { buildQuery } from 'ra-data-graphcool'; | ||
|
||
const overrideBuildQuery = buildQuery => (fetchType, resource, params) => { |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right !
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
packages/ra-data-graphcool/README.md
Outdated
if (resource === 'Command' && fetchType === 'GET_ONE') { | ||
return { | ||
// Use the default query variables and parseResponse | ||
...buildQuery, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@@ -58,6 +58,12 @@ export default async options => { | |||
...otherOptions | |||
} = merge({}, defaultOptions, options); | |||
|
|||
if (override && process.env.NODE_ENV === 'production') { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
e4cf27a
to
a1ddc52
Compare
Following #2243
override
optionbuildQuery
function in dialect packagesbuildQuery
to override specific queries