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

GraphQL Mesh with OpenAPI cannot find fetch even if it is defined using getExecutorForUnifiedGraph #1

Open
MichaelTheFear opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@MichaelTheFear
Copy link

MichaelTheFear commented Oct 17, 2024

I was trying to follow two parts of a tutorial for GraphQL Mesh:

  1. OpenAPI / Swagger Source Handlers
  2. Local Execution

Those two parts are and for some reason when I run them separately it works fine, but when I decide to join them together (meaning running the Mesh with the OpenAPI Source, and the getExecutorForUnifiedGraph) it gives me the following result:

{
  errors: [
    TypeError: You should have fetch defined in either the config or the context!
        at field.resolve (file:///usr/src/app/node_modules/@graphql-mesh/transport-rest/esm/directives/httpOperation.js:229:20)
        at executeField (file:///usr/src/app/node_modules/@graphql-tools/executor/esm/execution/execute.js:317:24)
        at executeFields (file:///usr/src/app/node_modules/@graphql-tools/executor/esm/execution/execute.js:265:28)
        at executeOperation (file:///usr/src/app/node_modules/@graphql-tools/executor/esm/execution/execute.js:225:18)
        at file:///usr/src/app/node_modules/@graphql-tools/executor/esm/execution/execute.js:65:45
        at new ValueOrPromise (/usr/src/app/node_modules/value-or-promise/build/main/ValueOrPromise.js:14:21)
        at executeImpl (file:///usr/src/app/node_modules/@graphql-tools/executor/esm/execution/execute.js:65:20)
        at execute (file:///usr/src/app/node_modules/@graphql-tools/executor/esm/execution/execute.js:48:12)
        at file:///usr/src/app/node_modules/@graphql-tools/executor/esm/execution/normalizedExecutor.js:12:37
        at new ValueOrPromise (/usr/src/app/node_modules/value-or-promise/build/main/ValueOrPromise.js:14:21) {
      path: [Array],
      locations: undefined,
      extensions: [Object: null prototype] {}
    }
  ],
  data: [Object: null prototype] { feed_availability: null }
}

I did find in this page that I can pass my own fetch as a parameter of the Mesh, but trying it out with node-fetch or whatwg-node/fetch won't solve it.

I did however find a temporary solution,which is adding this two lines inthe httpOperation.js file of the graphql-mesh

This one in the line 9:

import { createGraphQLError, memoize1 } from '@graphql-tools/utils';
import { Blob, File, FormData, URLSearchParams, fetch as whatwgFetch } from '@whatwg-node/fetch';
import { isFileUpload } from './isFileUpload.js';

And this one in the line 223:

operationLogger.debug(`=> Fetching `, fullPath, `=>`, requestInit);
const fetch = context?.fetch || globalFetch || whatwgFetch;
if (!fetch) {

Basically this solution is adding a fallback for the whatwgFetch in case there is no other fetch being define.

I was wondering if I should open this issue in the GraphQL Mesh repo, but since it works fine with the normal npx hive-gateway supergraph supergraph.js, and only has this error when using the getExecutorForUnifiedGraph I decided to open this here.

Here is a repo in which you can reproduce this error: hive-fetch-error

@dotansimha dotansimha transferred this issue from graphql-hive/console Oct 21, 2024
@dotansimha
Copy link
Member

Moved to the Hive's Gateway repo. @ardatan thoughts?

@enisdenjo enisdenjo added the bug Something isn't working label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants