Code Monkey home page Code Monkey logo

Comments (12)

milancermak avatar milancermak commented on June 8, 2024 12

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>
  );
}

from shopify-app-template-node.

hakimmazouz avatar hakimmazouz commented on June 8, 2024 3

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.

from shopify-app-template-node.

zinyosrim avatar zinyosrim commented on June 8, 2024 1

The code of @milancermak worked fine for me

from shopify-app-template-node.

ComicDansMS avatar ComicDansMS commented on June 8, 2024 1

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

from shopify-app-template-node.

zinyosrim avatar zinyosrim commented on June 8, 2024

I have the same issue

from shopify-app-template-node.

cdedreuille avatar cdedreuille commented on June 8, 2024

Hi, @paulomarg 👋 Any update on this one?

from shopify-app-template-node.

jhldreams avatar jhldreams commented on June 8, 2024

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

from shopify-app-template-node.

jhldreams avatar jhldreams commented on June 8, 2024

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 .

from shopify-app-template-node.

jhldreams avatar jhldreams commented on June 8, 2024

The code of @milancermak worked fine for me

thanks

from shopify-app-template-node.

ldv-orbyta avatar ldv-orbyta commented on June 8, 2024

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

from shopify-app-template-node.

github-actions avatar github-actions commented on June 8, 2024

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.

from shopify-app-template-node.

github-actions avatar github-actions commented on June 8, 2024

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!

from shopify-app-template-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.