Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jan 15, 2025
1 parent 3c1353c commit 4fa608c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/ra-data-graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ This is useful if you need to support custom dataProvider methods such as those
```tsx
import { Identifier, GET_LIST, GET_ONE } from 'ra-core';
import { RealTimeDataProvider } from '@react-admin/ra-realtime';
import { IntrospectedResource } from 'ra-data-graphql';
import { buildDataProvider, IntrospectedResource } from 'ra-data-graphql';

const subscriptions: {
topic: string;
Expand All @@ -256,7 +256,7 @@ export const dataProvider: RealTimeDataProvider = {
if (!resourceIntrospection) throw new Error(`Invalid resource ${resourceName}`);

const { query, queryName, variables } = buildQuery({ id, resource, resourceIntrospection });
const subscription = dataProvider.client
const subscription = baseDataProvider.client
.subscribe({ query, variables })
.subscribe(data =>
subscriptionCallback(data.data[queryName].event)
Expand All @@ -271,11 +271,16 @@ export const dataProvider: RealTimeDataProvider = {
return Promise.resolve({ data: null });
},
unsubscribe: async (topic: string, subscriptionCallback: any) => {
subscriptions = subscriptions.filter(
const subscriptionIndex = subscriptions.findIndex(
subscription =>
subscription.topic !== topic ||
subscription.subscriptionCallback !== subscriptionCallback
);

if (subscriptionIndex) {
subscriptions[subscriptionIndex].unsubscribe();
subscriptions = subscriptions.splice(subscriptionIndex, 1);
}
return Promise.resolve({ data: null });
},
}
Expand Down
1 change: 1 addition & 0 deletions packages/ra-data-graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ const getQueryOperation = query => {
export type GetIntrospection = () => Promise<IntrospectionResult>;
export type GraphqlDataProvider = DataProvider & {
getIntrospection: GetIntrospection;
client: ApolloClient<unknown>;
};

export default buildGraphQLProvider;

0 comments on commit 4fa608c

Please sign in to comment.