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

Hive Gateway: Subscription field must return Async Iterable. Received: undefined #136

Closed
masesor opened this issue Nov 14, 2024 · 3 comments · Fixed by #255
Closed

Hive Gateway: Subscription field must return Async Iterable. Received: undefined #136

masesor opened this issue Nov 14, 2024 · 3 comments · Fixed by #255
Labels
bug Something isn't working

Comments

@masesor
Copy link

masesor commented Nov 14, 2024

Hi,
I have a subgraph that follows this getting started example: https://the-guild.dev/graphql/yoga-server/docs/features/subscriptions#getting-started

type Query {
  hello: String
}

type Subscription {
  countdown(from: Int!): Int!
}
import { createServer } from 'node:http';
import { setTimeout as setTimeout$ } from 'node:timers/promises';

import { createSchema, createYoga } from 'graphql-yoga';

// Provide your schema
const yoga = createYoga({
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        hello: String
      }

      type Subscription {
        countdown(from: Int!): Int!
      }
    `,
    resolvers: {
      Query: {
        hello: () => 'world',
      },
      Subscription: {
        countdown: {
          // This will return the value on every 1 sec until it reaches 0
          async *subscribe(_, { from }) {
            for (let i = from; i >= 0; i--) {
              await setTimeout$(1000);
              yield { countdown: i };
            }
          },
        },
      },
    },
  }),
});

const server = createServer(yoga);
server.listen(21204, () => {
  console.info('Server is running on http://localhost:21204/graphql');
});

This works perfectly fine when connecting to this subgraph and running the subscription in graphiql.

I have a supergraph component that is defined with:

import { createPrefixTransform, defineConfig, loadGraphQLHTTPSubgraph } from '@graphql-mesh/compose-cli';

export const composeConfig = defineConfig({
  output: '_generated/supergraph.graphql',
  subgraphs: [
    {
      sourceHandler: loadGraphQLHTTPSubgraph('my-subgraph', {
        endpoint: 'http://localhost:21204/graphql',
        source: 'path/to/subgraph/schema.graphql',
      }),
      transforms: [
        createPrefixTransform({
          value: 'test_',
          includeRootOperations: true,
        }),
      ],
    },
  ],
});

Then I have my Hive Gateway:

gateway.config.ts


export const gatewayConfig = defineConfig({
  supergraph: async () => {
    try {
      const data = await fs.readFile(supergraphFile, 'utf-8');
      return data;
    } catch (err) {
      console.error('Error reading supergraph file:', err);
      throw err;
    }
  },
  playground: true,
  introspection: true,
  browser: true,
  healthCheckEndpoint: '/health',
  host: '0.0.0.0',
  port,
});

Running in docker-compose:

services:
  graphql-gateway:
    build:
      context: ..
      dockerfile: ./graphql-gateway/Dockerfile
    container_name: graphql-gateway
    ports:
      - '4000:4000'
    restart: always
    networks:
      - internal-network-proxy
    environment:
      SUPERGRAPH_FILE: ./supergraph.graphql
      SUPERGRAPH_PORT: 4000
      DEBUG: 1 # Enable if you require more detailed logs

networks:
  internal-network-proxy:
    external:
      name: internal_network

The Dockerfile copies the supergraph.graphql and gateway config into the container

When executing the query in the Hive Gateway GraphiQL, I get:

{
  "errors": [
    {
      "message": "Subscription field must return Async Iterable. Received: undefined.",
      "locations": [
        {
          "line": 1,
          "column": 29
        }
      ],
      "path": [
        "lt_countdown"
      ]
    }
  ]
}

From my understanding from the documentation, there doesn't seem to be any extra configuration that I need to set in the Hive Gateway or the Mesh Compose supergraph for subscriptions using SSE. Am I missing something?

Versions:

"graphql-yoga": "^5.10.2"
"@graphql-mesh/compose-cli": "^1.0.2"
Hive Gateway Docker: ghcr.io/ardatan/hive-gateway:latest

Thanks!

Edit: It seems if I remove includeRootOperations: true it works, however I do need to have prefixes on the subscription. Not sure why the prefix is breaking it

@kamilkisiela kamilkisiela transferred this issue from graphql-hive/console Nov 19, 2024
@enisdenjo enisdenjo added the bug Something isn't working label Nov 19, 2024
ardatan added a commit that referenced this issue Dec 3, 2024
@ardatan ardatan mentioned this issue Dec 3, 2024
@ardatan
Copy link
Member

ardatan commented Dec 3, 2024

Thanks for creating the issue and the details.
Could you help us reproducing here?
#255
Maybe it's been fixed already in the latest. You can also try it with the latest versions.

@ardatan
Copy link
Member

ardatan commented Dec 5, 2024

Closing the issue for now as it seems passing in our reproduction. We can reopen it if it still persists.

@masesor
Copy link
Author

masesor commented Dec 9, 2024

Hi, apologies for the delay in replying. Yes, after reviewing the docker image being used and updating to the latest I can confirm this issue is now resolved.

Thanks!

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

Successfully merging a pull request may close this issue.

3 participants