GraphQLWS在建立WebSocket连接之前设置cookie
应要求,我正在处理一个刮擦应用程序,该应用程序轻轻刮擦外部网站,该网站使用GraphQL和GraphQl-WS
package(因此,在WebSocket上使用GraphQl)。我以前从未使用过任何类型的GraphQl。
我正在尝试访问的网站使用会话cookie来验证用户。现在,我正在尝试在我的Nodejs应用程序中模拟这一点。我只是找不到为开放插座的初始HTTP请求设置cookie的方法。以下是我当前拥有的代码。
代码
import { createClient } from 'graphql-ws';
import WebSocket from 'ws';
const client = createClient({
url: 'wss://target.io/graphql',
webSocketImpl: WebSocket,
on: {
connected: (socket) => {
console.log("Connected!");
},
},
});
(async () => {
// Create subscription
})();
本身就可以正常工作,只要我不需要使用任何身份验证的订阅即可。我该如何制作它,以便在建立连接之前设置会话cookie?
Upon request I'm working on a scraping application that lightly scrapes a external website that makes use of graphql and the graphql-ws
package (so graphql over a websocket). I've never used any sort of graphql before.
The site I'm trying to gain access to makes use of a session cookie to authenticate users. Now I'm trying to simulate this in my NodeJS application. I just can't find a way of setting a cookie for the initial http request for opening the socket. Below is the code I currently have.
Code
import { createClient } from 'graphql-ws';
import WebSocket from 'ws';
const client = createClient({
url: 'wss://target.io/graphql',
webSocketImpl: WebSocket,
on: {
connected: (socket) => {
console.log("Connected!");
},
},
});
(async () => {
// Create subscription
})();
This in itself works fine, as long as I don't need to use any authenticated subscriptions. How can I make it so a session cookie is set before establishing a connection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论