leetcode/.scripts/graphql.mjs

24 lines
538 B
JavaScript
Raw Normal View History

import { request, GraphQLClient, gql } from "graphql-request";
const customFetch = require("fetch-cookie")(fetch);
export const client = new GraphQLClient("https://leetcode.com/graphql", {
headers: {
Referer: "https://leetcode.com",
},
fetch: customFetch,
});
const lastFetch = await customFetch("https://leetcode.com", {
redirect: "follow",
headers: {
Referer: "https://leetcode.com",
},
});
client.setHeader(
"x-csrftoken",
/csrftoken=([^;]+)/.exec(lastFetch.headers.get("set-cookie"))[1]
);
export { gql };