Help to find the error how to connect subscription when schema stitching.

I use apollo-server-express for graphql back-end. In it I plan to process only mutations, and redirect the query and subscription to hasura using schema stitching with introspection. Query through apollo-server to hasura work out normally and return the expected data.

But the subscription does not work and I get the following error: "Expected, iterative, but not for the field subscription_root.users" error logs graphql from server

With that on the server itself hasura events come: enter image description here

But apollo-server is indignant at the answer from hasura. Not the first day I suffer and I can not understand what the problem is.

In the editor hasura subscriptions work.

import { introspectSchema, makeExecutableSchema, makeRemoteExecutableSchema, mergeSchemas, transformSchema, FilterRootFields } from 'graphql-tools'; import { HttpLink } from 'apollo-link-http'; import nodeFetch from 'node-fetch'; import { resolvers } from './resolvers'; import { hasRoleResolver } from './directives'; import { typeDefs } from './types'; import { WebSocketLink } from 'apollo-link-ws'; import { split } from 'apollo-link'; import { getMainDefinition } from 'apollo-utilities'; import { SubscriptionClient } from 'subscriptions-transport-ws'; import * as ws from 'ws'; import { OperationTypeNode } from 'graphql'; interface IDefinitionsParams { operation?: OperationTypeNode, kind: 'OperationDefinition' | 'FragmentDefinition' } const wsurl = 'ws://graphql-engine:8080/v1alpha1/graphql'; const getWsClient = function (wsurl: string) { const client = new SubscriptionClient(wsurl, { reconnect: true, lazy: true }, ws); return client; }; const wsLink = new WebSocketLink(getWsClient(wsurl)); const createRemoteSchema = async () => { const httpLink = new HttpLink({ uri: 'http://graphql-engine:8080/v1alpha1/graphql', fetch: (nodeFetch as any) }); const link = split( ({ query }) => { const { kind, operation }: IDefinitionsParams = getMainDefinition(query); console.log('kind = ', kind, 'operation = ', operation); return kind === 'OperationDefinition' && operation === 'subscription'; }, wsLink, httpLink, ); const remoteSchema = await introspectSchema(link); const remoteExecutableSchema = makeRemoteExecutableSchema({ link, schema: remoteSchema }); const renamedSchema = transformSchema( remoteExecutableSchema, [ new FilterRootFields((operation, fieldName) => { return (operation === 'Mutation') ? false : true; // && fieldName === 'password' }) ] ); return renamedSchema; }; export const createNewSchema = async () => { const hasuraExecutableSchema = await createRemoteSchema(); const apolloSchema = makeExecutableSchema({ typeDefs, resolvers, directiveResolvers: { hasRole: hasRoleResolver } }); return mergeSchemas({ schemas: [ hasuraExecutableSchema, apolloSchema ] }); }; 

Link to code

If you need any additional data - I will provide.

    1 answer 1

    Corrected by installing graphql-tools version 4. It turns out the editor did not even notice that I do not have this dependency and just took node_modules the version that some other package installed. Problem version 3.x. Pull request where the error was fixed