Check if someone follows me (and yes I have the query thing already just tell me how to use it please and thank you)

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 :sob: as a function (especially one that returns true or false)

2 Likes
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

Quick question do you need the SID since the query doesn’t use connect sid at all?

4 Likes

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

how do i make whispers

You don’t, that’s a staff thing.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.