UNPKG

ra-data-graphql

Version:

A GraphQL data provider for react-admin

69 lines 3.58 kB
import { DataProvider } from 'ra-core'; import { ApolloClient, ApolloClientOptions, ApolloQueryResult, MutationOptions, WatchQueryOptions, QueryOptions, OperationVariables } from '@apollo/client'; import { IntrospectionOptions, IntrospectionResult } from './introspection'; export * from './introspection'; export declare const QUERY_TYPES: string[]; export declare const MUTATION_TYPES: string[]; export declare const ALL_TYPES: string[]; /** * Map dataProvider method names to GraphQL queries and mutations * * @example for the Customer resource: * dataProvider.getList() // query allCustomers() { ... } * dataProvider.getOne() // query Customer($id: id) { ... } * dataProvider.getMany() // query allCustomers($filter: { ids: [ids] }) { ... } * dataProvider.getManyReference() // query allCustomers($filter: { [target]: [id] }) { ... } * dataProvider.create() // mutation createCustomer($firstName: firstName, $lastName: lastName, ...) { ... } * dataProvider.update() // mutation updateCustomer($id: id, firstName: firstName, $lastName: lastName, ...) { ... } * dataProvider.delete() // mutation deleteCustomer($id: id) { ... } * // note that updateMany and deleteMany aren't mapped in this adapter */ export declare const defaultOptions: { resolveIntrospection: (client: ApolloClient<unknown>, options: IntrospectionOptions) => Promise<{ types: import("graphql").IntrospectionType[]; queries: import("graphql").IntrospectionField[]; resources: import("./introspection").IntrospectedResource[]; schema: import("graphql").IntrospectionSchema; }>; introspection: { operationNames: { GET_LIST: (resource: any) => string; GET_ONE: (resource: any) => string; GET_MANY: (resource: any) => string; GET_MANY_REFERENCE: (resource: any) => string; CREATE: (resource: any) => string; UPDATE: (resource: any) => string; DELETE: (resource: any) => string; }; exclude: undefined; include: undefined; }; }; export type BuildQueryResult = QueryOptions<OperationVariables, any> & { parseResponse: (response: ApolloQueryResult<any>) => any; }; export type BuildQuery = (name: string, resource: string, params: any) => BuildQueryResult; export type BuildQueryFactory = (introspectionResults: IntrospectionResult) => BuildQuery; export type GetQueryOptions = (resource: string, raFetchMethod: string) => Partial<QueryOptions<OperationVariables, any>>; export type GetMutationOptions = (resource: string, raFetchMethod: string) => Partial<MutationOptions<OperationVariables, any>>; export type GetWatchQueryOptions = (resource: string, raFetchMethod: string) => Partial<WatchQueryOptions<OperationVariables, any>>; export type Options = { client?: ApolloClient<unknown>; clientOptions?: Partial<ApolloClientOptions<unknown>>; introspection?: false | Partial<IntrospectionOptions>; override?: { [key: string]: (params: any) => BuildQueryResult; }; buildQuery: BuildQueryFactory; query?: GetQueryOptions; mutation?: GetMutationOptions; watchQuery?: GetWatchQueryOptions; }; declare const buildGraphQLProvider: (options: Options) => GraphqlDataProvider; export type GetIntrospection = () => Promise<IntrospectionResult>; export type GraphqlDataProvider = DataProvider & { getIntrospection: GetIntrospection; client: ApolloClient<unknown>; }; export default buildGraphQLProvider; //# sourceMappingURL=index.d.ts.map