-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework options alias prefix prefixes all queries and mutations. has to be configured on the backend as well BREAKING CHANGE: some (undocumented) options are no longer supported
- Loading branch information
Showing
13 changed files
with
388 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import merge from "lodash/merge"; | ||
import buildRaGraphqlDataProvider from "ra-data-graphql"; | ||
import { DELETE, DELETE_MANY, UPDATE, UPDATE_MANY } from "react-admin"; | ||
import { buildQueryFactory } from "./buildQuery"; | ||
import { Options } from "./types"; | ||
|
||
import { makeIntrospectionOptions } from "./utils/makeIntrospectionOptions"; | ||
|
||
export const defaultOptions: Options = { | ||
clientOptions: { uri: "/graphql" }, | ||
}; | ||
|
||
const buildDataProvider = (options: Options) => { | ||
return buildRaGraphqlDataProvider( | ||
merge( | ||
{}, | ||
defaultOptions, | ||
{ | ||
buildQuery: buildQueryFactory, | ||
introspection: makeIntrospectionOptions(options), | ||
}, | ||
options, | ||
), | ||
).then((graphQLDataProvider) => { | ||
return ( | ||
fetchType: string, | ||
resource: string, | ||
params: { [key: string]: any }, | ||
): Promise<any> => { | ||
// Temporary work-around until we make use of updateMany and deleteMany mutations | ||
if (fetchType === DELETE_MANY) { | ||
const { ids, ...otherParams } = params; | ||
return Promise.all( | ||
params.ids.map((id: string) => | ||
graphQLDataProvider(DELETE, resource, { | ||
id, | ||
...otherParams, | ||
}), | ||
), | ||
).then((results) => { | ||
return { data: results.map(({ data }: any) => data.id) }; | ||
}); | ||
} | ||
|
||
if (fetchType === UPDATE_MANY) { | ||
const { ids, ...otherParams } = params; | ||
return Promise.all( | ||
params.ids.map((id: string) => | ||
graphQLDataProvider(UPDATE, resource, { | ||
id, | ||
...otherParams, | ||
}), | ||
), | ||
).then((results) => { | ||
return { data: results.map(({ data }: any) => data.id) }; | ||
}); | ||
} | ||
return graphQLDataProvider(fetchType, resource, params); | ||
}; | ||
}); | ||
}; | ||
|
||
export default buildDataProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.