Skip to content

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

Open
@paales

Description

@paales

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: apollographql/apollo-client#9925 (comment)

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 ardatan/graphql-tools#4539

Then this comment ardatan/graphql-tools#4539 (comment)

And then ardatan/graphql-tools@ff3c071

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions