shopify-app-template-node icon indicating copy to clipboard operation
shopify-app-template-node copied to clipboard

Apollo Client

Open cdedreuille opened this issue 5 years ago • 10 comments

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?

cdedreuille avatar Feb 26 '21 16:02 cdedreuille

I have the same issue

zinyosrim avatar Mar 04 '21 15:03 zinyosrim

Hi, @paulomarg 👋 Any update on this one?

cdedreuille avatar Mar 09 '21 08:03 cdedreuille

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 avatar Mar 14 '21 20:03 milancermak

@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 ?

jhldreams avatar Aug 05 '21 07:08 jhldreams

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 .

jhldreams avatar Aug 10 '21 08:08 jhldreams

The code of @milancermak worked fine for me

zinyosrim avatar Aug 10 '21 08:08 zinyosrim

The code of @milancermak worked fine for me

thanks

jhldreams avatar Aug 10 '21 10:08 jhldreams

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.

hakimmazouz avatar Sep 09 '21 21:09 hakimmazouz

@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?

ComicDansMS avatar Mar 22 '22 11:03 ComicDansMS

It says to me: statusCode: 401, errors: '[API] Invalid API key or access token (unrecognized login or wrong password)'

ldv-orbyta avatar Jul 05 '22 09:07 ldv-orbyta

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.

github-actions[bot] avatar Oct 07 '22 02:10 github-actions[bot]

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!

github-actions[bot] avatar Oct 22 '22 02:10 github-actions[bot]