diff --git a/examples/demo/src/dataProvider/graphql.ts b/examples/demo/src/dataProvider/graphql.ts index ba0c6a10835..b8e0651c104 100644 --- a/examples/demo/src/dataProvider/graphql.ts +++ b/examples/demo/src/dataProvider/graphql.ts @@ -2,14 +2,10 @@ import { ApolloQueryResult } from '@apollo/client'; import buildApolloClient, { buildQuery as buildQueryFactory, } from 'ra-data-graphql-simple'; -import { BuildQuery } from 'ra-data-graphql'; +import { BuildQueryFactory } from 'ra-data-graphql'; import { DataProvider, DELETE } from 'react-admin'; import gql from 'graphql-tag'; -import { - IntrospectionField, - IntrospectionSchema, - IntrospectionType, -} from 'graphql'; +import { IntrospectionType } from 'graphql'; const getGqlResource = (resource: string) => { switch (resource) { @@ -36,20 +32,7 @@ const getGqlResource = (resource: string) => { } }; -type IntrospectionResource = IntrospectionType & { - [key: string]: IntrospectionField; -}; - -interface IntrospectionResults { - types: IntrospectionType[]; - queries: IntrospectionField[]; - resources: IntrospectionResource[]; - schema: IntrospectionSchema; -} - -const customBuildQuery = ( - introspectionResults: IntrospectionResults -): BuildQuery => { +const customBuildQuery: BuildQueryFactory = introspectionResults => { const buildQuery = buildQueryFactory(introspectionResults); return (type, resource, params) => { diff --git a/examples/demo/src/ra-data-graphql-simple.d.ts b/examples/demo/src/ra-data-graphql-simple.d.ts deleted file mode 100644 index adaa2fcbc9b..00000000000 --- a/examples/demo/src/ra-data-graphql-simple.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'ra-data-graphql-simple'; diff --git a/packages/ra-data-graphql-simple/package.json b/packages/ra-data-graphql-simple/package.json index ba337b3e858..1d45ad765a5 100644 --- a/packages/ra-data-graphql-simple/package.json +++ b/packages/ra-data-graphql-simple/package.json @@ -4,6 +4,7 @@ "description": "A GraphQL simple data provider for react-admin", "main": "lib/index.js", "module": "esm/index.js", + "types": "esm/index.d.ts", "sideEffects": false, "repository": { "type": "git", diff --git a/packages/ra-data-graphql-simple/src/index.ts b/packages/ra-data-graphql-simple/src/index.ts index 3a68a59d1fe..cb91fd98769 100644 --- a/packages/ra-data-graphql-simple/src/index.ts +++ b/packages/ra-data-graphql-simple/src/index.ts @@ -1,5 +1,5 @@ import merge from 'lodash/merge'; -import buildDataProvider, { Options } from 'ra-data-graphql'; +import buildDataProvider, { BuildQueryFactory, Options } from 'ra-data-graphql'; import { DataProvider, Identifier } from 'ra-core'; import defaultBuildQuery from './buildQuery'; @@ -9,7 +9,9 @@ const defaultOptions = { export const buildQuery = defaultBuildQuery; -export default (options: Options): Promise => { +export default ( + options: Omit & { buildQuery?: BuildQueryFactory } +): Promise => { return buildDataProvider(merge({}, defaultOptions, options)).then( defaultDataProvider => { return { diff --git a/packages/ra-data-graphql/src/buildApolloClient.ts b/packages/ra-data-graphql/src/buildApolloClient.ts index ac58c89f105..d501eeb122f 100644 --- a/packages/ra-data-graphql/src/buildApolloClient.ts +++ b/packages/ra-data-graphql/src/buildApolloClient.ts @@ -5,7 +5,7 @@ import { InMemoryCache, } from '@apollo/client'; -export default (options: ApolloClientOptions) => { +export default (options: Partial>) => { if (!options) { return new ApolloClient({ cache: new InMemoryCache().restore({}), diff --git a/packages/ra-data-graphql/src/index.ts b/packages/ra-data-graphql/src/index.ts index 3eb22e4c650..0c439a3a188 100644 --- a/packages/ra-data-graphql/src/index.ts +++ b/packages/ra-data-graphql/src/index.ts @@ -92,7 +92,8 @@ export type BuildQuery = ( resource: string, params: any ) => BuildQueryResult; -type BuildQueryFactory = ( + +export type BuildQueryFactory = ( introspectionResults: IntrospectionResult ) => BuildQuery; @@ -113,7 +114,7 @@ export type GetWatchQueryOptions = ( export type Options = { client?: ApolloClient; - clientOptions?: ApolloClientOptions; + clientOptions?: Partial>; introspection?: false | IntrospectionOptions; override?: { [key: string]: (params: any) => BuildQueryResult;