ardatan / ardatan/graphql-mesh

Running into import issues with @graphql-mesh/apollo-link

Open
#4,196 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.5k
Forks
363
Avg merge
6h 10m
Merged PRs (30d)
19

Description

### Issue workflow progress

_Progress of the issue based on the [Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [ ] 1. The issue provides a reproduction available on [Github](https://github.com/Urigo/graphql-mesh/tree/master/examples/hello-world), [Stackblitz](https://stackblitz.com/github/Urigo/graphql-mesh/tree/master/examples/hello-world) or [CodeSandbox](https://codesandbox.io/s/github/Urigo/graphql-mesh/tree/master/examples/hello-world)

> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure Mesh package versions under `package.json` matches yours.

- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review

---

**Describe the bug**

Running into this issue: https://github.com/apollographql/apollo-client/issues/9925#issuecomment-1191045735

**To Reproduce**
Steps to reproduce the behavior:

I'm using it in next.js, don't know if that makes a difference.

**Additional context**

If I follow the trail of the comments of the original issue

Which led me to this PR https://github.com/ardatan/graphql-tools/pull/4539

Then this comment https://github.com/ardatan/graphql-tools/pull/4539#issuecomment-1165434036

And then https://github.com/ardatan/graphql-tools/pull/4539/commits/ff3c071ca6de8ed7768d538089c3d3891218d77a

After applying the following patch, it seems to work as expected:

```patch
diff --git a/node_modules/@graphql-mesh/apollo-link/index.mjs b/node_modules/@graphql-mesh/apollo-link/index.mjs
index d1e2b34..fbf27e3 100644
--- a/node_modules/@graphql-mesh/apollo-link/index.mjs
+++ b/node_modules/@graphql-mesh/apollo-link/index.mjs
@@ -1,6 +1,8 @@
-import { ApolloLink, Observable } from '@apollo/client/core';
import { isAsyncIterable } from '@graphql-tools/utils';
import { getOperationAST } from 'graphql';
+import * as apolloImport from '@apollo/client';
+
+const apollo = apolloImport?.default ?? apolloImport;

const ROOT_VALUE = {};
function createMeshApolloRequestHandler(options) {
@@ -10,7 +12,7 @@ function createMeshApolloRequestHandler(options) {
throw new Error('GraphQL operation not found');
}
const operationFn = operationAst.operation === 'subscription' ? options.subscribe : options.execute;
- return new Observable(observer => {
+ return new apollo.Observable(observer => {
Promise.resolve()
.then(async () => {
const results = await operationFn(operation.query, operation.variables, operation.getContext(), ROOT_VALUE, operation.operationName);
@@ -38,7 +40,7 @@ function createMeshApolloRequestHandler(options) {
});
};
}
-class MeshApolloLink extends ApolloLink {
+class MeshApolloLink extends apollo.ApolloLink {
constructor(options) {
super(createMeshApolloRequestHandler(options));
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the import failure in a Next.js application using @graphql-mesh/apollo-link, then inspect the generated node_modules/@graphql-mesh/apollo-link/index.mjs entry point and the linked Apollo Client issue and graphql-tools PR. Done means the package imports and runs without a node_modules patch, with a failing test or reproduction demonstrating the corrected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, next.js, typescript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.