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

Fix "dataProvider should return a rejected Promise" error in GraphQL providers #5795

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions packages/ra-data-graphql/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,38 @@ export default async options => {
`${resource}.${aorFetchType}`
);

const { parseResponse, ...query } = overriddenBuildQuery
? {
...buildQuery(aorFetchType, resource, params),
...overriddenBuildQuery(params),
}
: buildQuery(aorFetchType, resource, params);
try {
const { parseResponse, ...query } = overriddenBuildQuery
? {
...buildQuery(aorFetchType, resource, params),
...overriddenBuildQuery(params),
}
: buildQuery(aorFetchType, resource, params);

const operation = getQueryOperation(query.query);

if (operation === 'query') {
const apolloQuery = {
...query,
fetchPolicy: 'network-only',
...getOptions(otherOptions.query, aorFetchType, resource),
};

return client
.query(apolloQuery)
.then(response => parseResponse(response));
}

const operation = getQueryOperation(query.query);

if (operation === 'query') {
const apolloQuery = {
...query,
fetchPolicy: 'network-only',
...getOptions(otherOptions.query, aorFetchType, resource),
mutation: query.query,
variables: query.variables,
...getOptions(otherOptions.mutation, aorFetchType, resource),
};

return client
.query(apolloQuery)
.then(response => parseResponse(response));
return client.mutate(apolloQuery).then(parseResponse);
} catch (e) {
return Promise.reject(e);
}

const apolloQuery = {
mutation: query.query,
variables: query.variables,
...getOptions(otherOptions.mutation, aorFetchType, resource),
};

return client.mutate(apolloQuery).then(parseResponse);
};

raDataProvider.observeRequest = (aorFetchType, resource, params) => {
Expand Down