graphql-mesh icon indicating copy to clipboard operation
graphql-mesh copied to clipboard

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

Open paales opened this issue 1 year ago • 0 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

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:

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

paales avatar Jul 26 '22 07:07 paales