Не получаю данных по подписке Apollo Client

Пытаюсь получить данные по подписке. Сервер данные отдает, если смотреть через Explorer.

Клиент:

const httpLink = createHttpLink({
    uri
});

const wsLink =
  typeof window !== "undefined"
    ? new GraphQLWsLink(
        createClient({
            url,
            keepAlive: 30000,
            retryAttempts: Infinity,
            retryWait: async function waitForServerHealthyBeforeRetry() {
                await new Promise((resolve) =>
                    setTimeout(resolve, 1000 + Math.random() * 3000)
                );
            },
            on: {
                connected: () => console.log("Connected client!"),
                closed: () => console.log("Closed ws connection!"),
            },
        })
    )
    : null;

const splitLink =
  typeof window !== "undefined" && wsLink != null
    ? split(
        ({ query }) => {
            const def = getMainDefinition(query);
            return (
                def.kind === "OperationDefinition" &&
                def.operation === "subscription"
            );
        },
        wsLink,
        httpLink
    )
    : httpLink;

const authLink = setContext((_, { headers }) => {
    const {token} = useTokenFromCookie();
    return {
        headers: {
            ...headers,
            authorization: token ? `Bearer ${token()}` : "",
        }
    }
});

const client = new ApolloClient({
    link: authLink.concat(splitLink),
    cache: new InMemoryCache({addTypename: false}),
    defaultOptions: {
        mutate: { errorPolicy: 'all' },
    },
});

gql:

subscription ReadRegisterData($equipmentId: Int!, $addressRegistry: Int!) {
    readRegisterData(equipment_id: $equipmentId, address_registry: $addressRegistry) {
        equipment_id
        address_registry
        type_of
        data_from_controller
    }
}

Хук:

const useSubscriptionReadRegisterData = (equipment_ip:number, address_registry: number) => {
const { data, error, loading} = useSubscription(READ_REGISTER_DATA, {
    variables: {
        equipmentIp: equipment_ip,
        addressRegistry: address_registry
    }
});

console.log("data", data)

const dataRegisterSubscription = (data) ? data.readRegisterData : null;

return { dataRegisterSubscription, error, loading }
}

export default useSubscriptionReadRegisterData;

Ответы (0 шт):