Apollo Client
I just started on a new app for Shopify and as I'm new to Apollo I was really surprise to see that react-apollo is not really supported. Apollo is asking to use @apollo-client instead.
Is this something you are planning to update?
I have the same issue
Hi, @paulomarg 👋 Any update on this one?
I was experimenting with using @apollo/client as well. This works for me:
// _app.js
import { ApolloClient, ApolloProvider, InMemoryCache, createHttpLink } from '@apollo/client';
//...
function MyProvider(props) {
const app = useAppBridge();
const client = new ApolloClient({
cache: new InMemoryCache(),
link: createHttpLink({
credentials: 'include',
headers: {
"Content-Type": "application/graphql"
},
fetch: authenticatedFetch(app)
})
});
const Component = props.Component;
return (
<ApolloProvider client={client}>
<Component {...props} />
</ApolloProvider>
);
}
And using useQuery in a component:
import { gql, useQuery } from '@apollo/client';
const GET_SHOP_NAME = gql`
query {
shop {
id
name
email
}
}
`
export default function ShopInfo() {
const { loading, error, data } = useQuery(GET_SHOP_NAME);
if (loading) return <div>Loading...</div>;
if (error) return <div>{error.message}</div>
console.log(data)
return (
<p>OK</p>
);
}
@milancermak Hi, I also use new Apollo/Client, but when do a query throw useQuery , the graphql post request occured cros error. I see your code in new ApolloClient ,you ad a authenticatedFetch, Does this line must be included ?
any update of this issue ?? @paulomarg i'm new to shopify app dev, find the react-apollo has been deprecated. I try to change it to Apollo/Client, but face query request keep loading , no error and no data return .
The code of @milancermak worked fine for me
I keep getting this error even while using the code provided by @milancermak
Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options.
@milancermak you bloody legend. This took me way too long to find.
I'm also wondering what the hold up on Migrating to @apollo/client is?
It says to me: statusCode: 401, errors: '[API] Invalid API key or access token (unrecognized login or wrong password)'
This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.
We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.
If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines
Thank you!