Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: apollo-client not working with Nextjs #413

Closed
yashtotla opened this issue Apr 3, 2023 · 4 comments
Closed

Bug: apollo-client not working with Nextjs #413

yashtotla opened this issue Apr 3, 2023 · 4 comments

Comments

@yashtotla
Copy link

I tried using @graphprotocol/client-apollo with @apollo/client in the default nextjs app.

I modified the default _app.tsx file so that it matches with the apolllo client example

The build fails with the error https://github.com/yashtotla/nextjs-apollo-graphprotocol-issue/blob/main/build-error.txt

Example repo to reproduce the error: https://github.com/yashtotla/nextjs-apollo-graphprotocol-issue

Repo is set up using create-next-app with typescript. Node version 16. Package manager: yarn

@yashtotla
Copy link
Author

yashtotla commented Apr 3, 2023

I could get the build to not fail by using MeshApolloLink instead of GraphApolloLink

// import { GraphApolloLink } from "@graphprotocol/client-apollo";
const { MeshApolloLink } = require("@graphql-mesh/apollo-link");

And initializing the client as follows

const subGraphClient = new ApolloClient({
  link: new MeshApolloLink(GraphClient),
  cache: new InMemoryCache()
});

But this does not seem ideal

@ardatan
Copy link
Member

ardatan commented Apr 3, 2023

I see you are importing Mesh's Apollo Link with require. What happens when you import GraphClient's Apollo Link in the same way?

@yashtotla
Copy link
Author

yashtotla commented Apr 3, 2023

@ardatan

If I change the import to
const { GraphApolloLink } = require("@graphprotocol/client-apollo");

The build is successful. The code compiles with these warnings

./node_modules/@graphql-mesh/utils/esm/defaultImportFn.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/@graphql-mesh/utils/esm/defaultImportFn.js
./node_modules/@graphql-mesh/utils/esm/index.js
./.graphclient/index.ts

./node_modules/@graphql-tools/url-loader/esm/index.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/@graphql-tools/url-loader/esm/index.js
./node_modules/@graphql-mesh/graphql/esm/index.js
./.graphclient/index.ts

@ubinatus
Copy link

ubinatus commented Apr 4, 2023

Hi @yashtotla . Had the same issue. Undesirable dirty logs but it's currently working.

See #303 and ardatan/graphql-mesh#2256.

@ardatan ardatan closed this as completed Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants