Skip to content

Commit

Permalink
Merge pull request #6724 from marmelab/fix-graphql-simple-types
Browse files Browse the repository at this point in the history
Fix Graphql Providers Types
  • Loading branch information
djhi authored Oct 25, 2021
2 parents 4b0530d + 4602bcc commit 85406f6
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
23 changes: 3 additions & 20 deletions examples/demo/src/dataProvider/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand Down
1 change: 0 additions & 1 deletion examples/demo/src/ra-data-graphql-simple.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/ra-data-graphql-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions packages/ra-data-graphql-simple/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,7 +9,9 @@ const defaultOptions = {

export const buildQuery = defaultBuildQuery;

export default (options: Options): Promise<DataProvider> => {
export default (
options: Omit<Options, 'buildQuery'> & { buildQuery?: BuildQueryFactory }
): Promise<DataProvider> => {
return buildDataProvider(merge({}, defaultOptions, options)).then(
defaultDataProvider => {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-data-graphql/src/buildApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
InMemoryCache,
} from '@apollo/client';

export default (options: ApolloClientOptions<unknown>) => {
export default (options: Partial<ApolloClientOptions<unknown>>) => {
if (!options) {
return new ApolloClient({
cache: new InMemoryCache().restore({}),
Expand Down
5 changes: 3 additions & 2 deletions packages/ra-data-graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export type BuildQuery = (
resource: string,
params: any
) => BuildQueryResult;
type BuildQueryFactory = (

export type BuildQueryFactory = (
introspectionResults: IntrospectionResult
) => BuildQuery;

Expand All @@ -113,7 +114,7 @@ export type GetWatchQueryOptions = (

export type Options = {
client?: ApolloClient<unknown>;
clientOptions?: ApolloClientOptions<unknown>;
clientOptions?: Partial<ApolloClientOptions<unknown>>;
introspection?: false | IntrospectionOptions;
override?: {
[key: string]: (params: any) => BuildQueryResult;
Expand Down

0 comments on commit 85406f6

Please sign in to comment.