fetch graphql query from external server

fetch graphql query from external server


0

i’m trying to fetch some leetcode stats using leetcode’s graphql schema. when i enter the query in the browser, it gives me a response, but it’s not responding to me when i use axios.

here’s the query i enter in the browser:

https://leetcode.com/graphql?query=query {
 questionSubmissionList(
    offset: 0,
    limit: 20,
    questionSlug: "two-sum"
  ) {
    lastKey
    hasNext
    submissions {
      id
      title
      titleSlug
      status
      statusDisplay
      lang
      langName
      runtime
      timestamp
      url
      isPending
      memory
    }
  }
}

and here’s what i have in my code:

    let url = `https://leetcode.com/graphql`;
    const fetchSubmissionList = async (questionSlug) => {
        let query = `
            query questionSubmissionList(
               offset: 0,
               limit: 20,
               questionSlug: $questionSlug
             ) {
                lastKey
                hasNext
                submissions {
                    id
                    title
                    titleSlug
                    status
                    statusDisplay
                    lang
                    langName
                    runtime
                    timestamp
                    url
                    isPending
                    memory
                }
            }
        }
        `
        const data = await axios.post(url, {
            query: query,
            variables: {
                questionSlug: questionSlug
            }
        }, {
            headers: {
                'Content-Type': 'application/graphql',
                'Access-Control-Allow-Origin':  'https://localhost:5173/',
                'Access-Control-Allow-Methods': 'POST',
                'Access-Control-Allow-Headers': 'Content-Type, Authorization'
            },
        })
        console.log(data)
    }

I’m getting no cors errors whenever i run the query.
i saw online that I’m supposed to implement no cors server side, but since i don’t have access to the server, i obviously can’t change anything over there

one possible reason for this that i can think of is that, on the browser side, I’m logged in using my leetcode account, but i might not be when i use axios. however, when i go incognito, i still get a response (albeit an empty one) from leetcode.

thanks


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *