apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.37k stars 2.66k forks source link

Appolo Client with shopify #11993

Closed Zainali005 closed 2 months ago

Zainali005 commented 2 months ago

Issue Description

I am using Appolo client with shopify because i have to use graphql shopify api so i am init the appolo client in my next application but the issue is i have done all the error showing is Appolo Error and in network tab showing CORS error . Could any one help me please to resove this

Link to Reproduction

localhost

Reproduction Steps

import { ApolloClient, InMemoryCache, HttpLink, ApolloLink, } from "@apollo/client"; import { setContext } from "@apollo/client/link/context";

const httpLink = new HttpLink({ uri: "https://quickstart-d41428**.myshopify.com/admin/api/2024-07/graphql.json", });

const authLink = setContext((_, { headers }) => { return { headers: { ...headers, "content-type": "application/json", "X-Shopify-Access-Token": "shpat_f5306c05713bc9197a504099d11****", }, }; });

const client = new ApolloClient({ link: ApolloLink.from([authLink, httpLink]), cache: new InMemoryCache(), });

export default client;

@apollo/client version

3.11.2

phryneas commented 2 months ago

A CORS error means that your GraphQL server doesn't tell your browser "hey, that webpage is allowed to access me".

It is something you need to configure on your server - for example when your website is running at localhost:3000, you have to configure your shopify server to say "yes, localhost:3000 is a valid origin!".

That said, this is nothing we can help you with - it's not a client configuration issue, but a server configuration issue - and I don't have personal experience with Shopify.

From what I can gather from a quick google, it might even be the case that Shopify generally doesn't allow access from any frontend and you might need to set up your own backend to act as a middleman - at least that's how https://community.shopify.com/c/online-store-and-theme/using-apis-from-a-different-origin-domain/td-p/502781 reads to me. Keep in mind though, that that answer is 5 years old and things might have changed since.

I would recommend you to do some more research on this on the Shopify side.

As there is unfortunately nothing we really can do for you here, I'm going to close this issue - good luck!

github-actions[bot] commented 2 months ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.