Hello friends.
I try to realize the topic of Subscriptions in the documentation , by replacing the express server by createhandler in lambda (Getting Started with Subscriptions - Neo4j GraphQL Library)
import { createServer } from 'http';
import express from 'express';
import { ApolloServer, gql } from 'apollo-server-lambda';
import { WebSocketServer } from 'ws'; //ok1
import { useServer } from 'graphql-ws/lib/use/ws'; //ok2
import DatabaseManager from '../../services/database/DatabaseManager';
import { Neo4jGraphQL, Neo4jGraphQLSubscriptionsSingleInstancePlugin} from '@neo4j/graphql';
import { ApolloServerPluginDrainHttpServer } from 'apollo-server-core';
const typeDefs = gql`
type Movie {
title: String!
description: String!
}
`;
const driver = DatabaseManager.driver ;
const neoSchema = new Neo4jGraphQL({
typeDefs,
driver,
plugins: {
subscriptions: new Neo4jGraphQLSubscriptionsSingleInstancePlugin(),
},})
const app = express();
const httpServer = createServer(app);
const wsServer = new WebSocketServer({
server: httpServer,
path: "/graphql"
});
const initServer = () => {
return neoSchema.getSchema().then(async (schema)=>{
const serverCleanup = useServer({schema}, wsServer);
const server = new ApolloServer({
schema,
plugins: [
ApolloServerPluginDrainHttpServer({
httpServer
}),
{
async serverWillStart() {
return {
async drainServer() {
await serverCleanup.dispose();
},
};
},
},
],
});
const handlerMiddleware = server.createHandler()
return handlerMiddleware
})
}
export const handler = async (event:any, context: any, callback: any) => {
const serverHandler = await initServer();
return serverHandler({...event}, context, callback)
};
But when I try to realize Subscription in (Studio)
subscription MovieCreated($where: MovieSubscriptionWhere) {
movieCreated(where: $where) {
event
timestamp
createdMovie {
title
description
}
}
}
with variables:
{
"where": {
"title": "new film created"
}
}
I have this error message : {
"message": "server must support graphql-ws or subscriptions-transport-ws protocol"
}
I don't understand why , could you help me please .