我正在尝试使用 hasura 创建一个 graphql 订阅,请遵循以下示例:使用 nodejs 测试 GraphQL 订阅的样板,只需为 trypescript 添加类型,如果我直接使用 nodemon 运行它可以正常工作,并获取我想要的数据但如果尝试制作 tsc 我收到以下错误:
我的订阅代码是:
/***** Setup a GraphQL subscription observable ******************************/
import { DocumentNode, execute, GraphQLRequest } from 'apollo-link';
import { WebSocketLink } from 'apollo-link-ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import ws from 'ws';
const getWsClient = (wsURL: string) => {
const client = new SubscriptionClient(
wsURL, {
reconnect: true, connectionParams: () => {
return {
headers: {
'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET
}
}
}
}, ws
);
return client;
};
// wsURL: GraphQL endpoint
// query: GraphQL query (use gql`` from the 'graphql-tag' library)
// variables: Query variables object
const createSubscription = (wsURL: string, query: DocumentNode, variables: Record<string, any>) => {
const link = new WebSocketLink(getWsClient(wsURL));
return execute(link, { query, variables } as GraphQLRequest);
};
export default createSubscription
我已经更新了“nodemon”的打字稿:“^2.0.15”,“ts-node”:“^10.2.1”,“打字稿”:“^4.4.2”
有人有什么想法吗?
提前致谢。