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 Graphql Providers Types #6724

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
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
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