constitutional-coralC
Refine2y ago
16 replies
constitutional-coral

Subscription

I have a case where I want to subscribe to Notifications - meaning when a new notification data is added to the table, I want to show an alert.

On my header I have this:
const { selectProps: alertSelectProps, queryResult: alertQueryResult } = useAlerts();

return (
<Layout.Header style={headerStyles}>
<Space align="center" size="middle">
<Notifications data={actualData}/>
<CurrentUser />
</Space>
</Layout.Header>
);

And the notification handles the data.
Now inside the useAlers I have the query:
import { useSelect } from "@refinedev/antd";
import { GetFieldsFromList } from "@refinedev/nestjs-query";

import gql from "graphql-tag";
import { AlertsQuery } from "@/graphql/types";

const ALERTS_QUERY = gql query Alerts( $paging: OffsetPaging! $filter: AlertFilter! $sorting: [AlertSort!] ) { alerts(paging: $paging, filter: $filter, sorting: $sorting) { nodes { id gateway{ id serialNumber } vehicle{ id vin make model } driver{ id name } createdAt active eventType description } totalCount } } ;

export const useAlerts = () => {
return useSelect<AlertsQuery>({
resource: "alerts",
pagination: {
pageSize: 5,
},
sorters: [{ field: "created_at", order: "desc" }],
meta: {
gqlQuery: ALERTS_QUERY,
},
liveMode: "auto",
});
};

However I noticed that it seems that the subscription is not working well.
Is there another place where I should use hookd like this to keep getting updated data onto my refine project?
Was this page helpful?