doxr
(Izaan Shaik)
July 29, 2023, 9:43pm
1
Hi AMC,
I am bad with GQL but I really want to use it in my project. So I want to use this query thing that I found that Ironcladdev used in Replyte (Chat App) - Replit
The query as I found:
query user($id: Int!) {
user(id: $id) {
isFollowingCurrentUser
}
}
I don’t know how to use this since it doesn’t mention anything about a user at all, and I don’t know what to put in $id
Ironcladdev used it like this:
export default async function parseRoles(user) {
const id = Number(user.id);
let isFollowing = await gql.raw({
query: `query user($id: Int!) { user(id: $id) { isFollowingCurrentUser } }`,
variables: {
id
}
});
const boostedRole = (isFollowing.data && isFollowing.data.user && isFollowing.data.user.isFollowingCurrentUser) || (user.username === "IroncladDev");
How do I use it as a function (especially one that returns true or false)
2 Likes
9pfs
July 29, 2023, 9:55pm
2
if(!fetch) const fetch = require("cross-fetch");
async function isFollowing(username) {
let req = await fetch("https://replit.com/graphql", {
method: "POST",
headers: {
"X-Requested-With": "replit",
"Referer": "https://replit.com",
"Cookie": `connect.sid=${process.env.SID}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
query: `query isFollowing($username:String!){user:userByUsername(username:$username){isFollowingCurrentUser}}`,
variables: {
username
}
}
});
let res = await req.json();
return res.data&&res.data&&res.data.isFollowing&&res.data.isFollowing.isFollowingCurrentUser;
}
That should work afaik
7 Likes
doxr
(Izaan Shaik)
July 29, 2023, 9:56pm
3
Quick question do you need the SID since the query doesn’t use connect sid at all?
4 Likes
9pfs
July 29, 2023, 9:57pm
4
You need a valid SID for your account. Otherwise, since a user who’s logged out can’t be followed, it’ll probably always return false.
7 Likes
Firepup650
(Firepup Sixfifty)
July 30, 2023, 3:04am
10
You don’t, that’s a staff thing.
2 Likes
system
(system)
Closed
August 6, 2023, 3:05am
11
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.