GraphQL query in React for Sorare data (running locally)

22 Views Asked by At

I'm trying to make queries work, It seems like even when I'm overcoming the CORS issue I still get 403.

Here's my code:

import { ApolloClient, InMemoryCache, gql } from '@apollo/client';

const proxyUrl = 'https://cors-anywhere.herokuapp.com/';
const apiUrl = 'https://api.sorare.com/federation/graphql';

const client = new ApolloClient({
  uri: proxyUrl + apiUrl,
  fetchOptions: {
    mode: 'no-cors',
    headers: {
      'APIKEY': '<ive_added_my_key_here>'
    }
  },
  cache: new InMemoryCache(),
});

function App() { 
   const GET_PLAYERS = client
    .query({
        query: gql`
            query GetPlayers {
                players {
                    id
                    name
                    position
                    team {
                        id
                        name
                    }
                }
            }
        `,
    })
    .then((result) => {
        console.log(result);
        return result;
    });
}

Tried to run ANY query using the sorare graphQL api on my react app.

I expected to see result to my console.log.

I got 403.

0

There are 0 best solutions below