Updated version of server.ts file with graphql

Is there an updated version of the server.ts file for graphql subscriptions? The subscriptions section in the docs + the examples were very helpful, but the server.ts file in the examples looks outdated. It is still using the deprecated @redwoodjs/fastify, and nothing seems to work using that package. I’m looking to do something like the following without @redwoodjs/fastify but not sure the best route: redwoodjs-streaming-realtime-demos/api/src/server.ts at 32cdbe7579803a2d1b9c7581268fa20137b26285 · redwoodjs/redwoodjs-streaming-realtime-demos · GitHub

Thank you in advance!

@dthyresson sounds like a DT thing!

Could you help here please? :slight_smile:

1 Like

Hi @jdrorrer and thanks for trying our Redwood Realtime and GraphQL subscriptions.

I just setup a new project and following the doc instructions here: Realtime | RedwoodJS Docs

yarn create redwood-app --ts rw-sub-example
cd  rw-sub-example
yarn rw setup server-file
yarn rw setup realtime 

I elected to install the default examples.

I also setup realtime in the GraphQL handler:

import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'
import { realtime } from 'src/lib/realtime'

export const handler = createGraphQLHandler({
  loggerConfig: { logger, options: {} },
  onException: () => {
    // Disconnect from your database with an unhandled exception.

I then launched dev:

yarn rw dev  

And then GraphQL Playground to subscribe to room 1 messages:

And then sent a message

which I received:

The server file that the setup creates is:

import { createServer } from '@redwoodjs/api-server'

import { logger } from 'src/lib/logger'

async function main() {
  const server = await createServer({

  await server.start()


I see that the examples I made last September or so (7 months ago) in are old … and

Please see our showcase realtime app for examples of subscriptions and live queries. It also demonstrates how you can handle streaming responses, like those used by OpenAI chat completions.

in the docs should make a note of that.

Could you try the setup commands above and see if the server file you then get is more what you need?

1 Like

@dthyresson thank you so much! This appears to be exactly what I was looking for. I will try this today and get back to you.

1 Like