awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
919 stars 266 forks source link

Error in basic react example of AWSAppSyncClient . 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. #617

Closed mm87642 closed 2 years ago

mm87642 commented 3 years ago

I am tring out the basic react example of aws-mobile-appsync-sdk-js

import AWSAppSyncClient from 'aws-appsync'
import AppSyncConfig from './aws-exports'
import { ApolloProvider } from 'react-apollo'
import { Rehydrated } from 'aws-appsync-react' // this needs to also be installed when working with React

import App from './App'

const client = new AWSAppSyncClient({
  url: AppSyncConfig.graphqlEndpoint,
  region: AppSyncConfig.region,
  auth: {
    type: AppSyncConfig.authenticationType,
    apiKey: AppSyncConfig.apiKey,
    // jwtToken: async () => token, // Required when you use Cognito UserPools OR OpenID Connect. token object is obtained previously
  }
})

const WithProvider = () => (
  <ApolloProvider client={client}>
    <Rehydrated>
      <App />
    </Rehydrated>
  </ApolloProvider>
)

export default WithProvider

and getting following error

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.

here is my package.json

"dependencies": {
    "@ant-design/icons": "^4.3.0",
    "@apollo/client": "^3.3.7",
    "@apollo/react-hooks": "^4.0.0",
    "@aws-amplify/ui-react": "^0.2.33",
    "@sentry/react": "^5.30.0",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.20",
    "@types/node": "^14.14.22",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "antd": "^4.10.2",
    "apollo-cache-inmemory": "^1.6.6",
    "apollo-client": "^2.6.10",
    "apollo-link": "^1.2.14",
    "apollo-link-context": "^1.0.20",
    "apollo-link-http": "^1.5.17",
    "aws-amplify": "^3.3.13",
    "aws-appsync": "^4.0.2",
    "aws-appsync-auth-link": "^3.0.2",
    "aws-appsync-react": "^4.0.2",
    "aws-appsync-subscription-link": "^3.0.4",
    "bootstrap": "^4.6.0",
    "i18next": "^19.8.4",
    "i18next-browser-languagedetector": "^6.0.1",
    "i18next-http-backend": "^1.0.21",
    "node-sass": "^4.14.1",
    "react": "^17.0.1",
    "react-apollo": "^2.5.8",
    "react-app-rewired": "^2.1.8",
    "react-bootstrap": "^1.4.3",
    "react-dom": "^17.0.1",
    "react-i18next": "^11.8.5",
    "react-otp-input": "^2.3.0",
    "react-player": "^2.8.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.1",
    "ts-loader": "^8.0.14",
    "typescript": "^4.1.3",
    "web-vitals": "^0.2.4"
  }

would appreciate any help. Facing random issues in getting the basic code run. probably there is some issues due to dependencies updated.

Thanks.

dpilch commented 2 years ago

Closing as stale.