#problem with subscriptions setup

9 messages · Page 1 of 1 (latest)

undone cipher
#

hello everyone, I'm trying to follow the documentation to enable subscriptions using "graphql-ws", problem is i'm getting a type error for the "subscriptions" key in the GraphqlMdule configuration.

I'm also using neo4j Graphql but I'm providing it as a factory, so I don't think it's interfering somehow.

Sorry for the nooby question but I can't find a way around this..

gql.module.ts

import { Module } from '@nestjs/common';
import neo4j from "neo4j-driver";
import { Neo4jGraphQL } from "@neo4j/graphql";
import { typeDefs } from './type-defs';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';


export const gqlProviderFactory = async () => {

    const { NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD } = process.env;

    const driver = neo4j.driver(
      NEO4J_URI,
      neo4j.auth.basic(NEO4J_USERNAME, NEO4J_PASSWORD)
    );

    const neoSchema = new Neo4jGraphQL({
      typeDefs,
      driver
    });
  
    const schema = await neoSchema.getSchema();

    await neoSchema.assertIndexesAndConstraints({
      options: { create: true }
    });
  
    return {
      playground: true,
      schema
    };
  };
  
  @Module({
    imports: [
      GraphQLModule.forRootAsync<ApolloDriverConfig>({
        driver: ApolloDriver,
        subscriptions: {
          'graphql-ws': true
        }
        // useFactory: gqlProviderFactory,
      })
    ]
  })
  export class GqlModule {
  }
sweet stream
#

If that's your options object, change forRootAsync to forRoot

undone cipher
sweet stream
#

If you want to use the factory, the options returned by the factory would contain everything you would normally pass to the forRoot

#

So you'd move the driver and subscriptions property to the return of the `gqlProviderFactory|

undone cipher
sweet stream
#

Oh, shoot, right, driver stays at top level, subscriptions should be moved

undone cipher
#

now i'm returning the subscription property from the factory, but i still can't use subscriptions (error Could not connect to websocket endpoint )