Skip to content

fast-map breaks mercurius #251

Open
Open
@VirtuousDeath

Description

@VirtuousDeath

I am having toruble using rtc-switch which depends on collections.
The fast-map file break the fastify graphql plugin.
I wonder there is a possible solution for this.
To reproduce:

index.ts

'use strict'

import Fastify from 'fastify'
import mercurius from 'mercurius'
import cors from '@fastify/cors'
import fastifySocketIo from 'fastify-socket.io'
import fastifySwagger from '@fastify/swagger'
import board from 'rtc-switch'

const app = Fastify({
  logger: {
    level: 'info',
    file: './logs/log'
  }
})

app.register(mercurius, {
  schema: `
  type Query {
    health: Boolean
  }

  type Mutation {
    health: Boolean
  }

  type Subscription {
    health: Boolean
  }
`,
  resolvers: {
    Query: {
      health: async (root, args, ctx, info) => true
    },
    Mutation: {
      health: async (root, args, ctx, info) => true
    },
    Subscription: {
      health: async (root, args, ctx, info) => true
    }
  },
  graphiql: 'playground'
})

app.register(cors, {
  origin: "*",
  methods: ["GET", "POST", "PUT", "PATCH", "DELETE"],
})

app.register(fastifySocketIo, {
  transports: ['websocket'],
  cors: {
    origin: "http://localhost:3000",
    methods: ["GET", "POST", "PUT", "PATCH", "DELETE"],
  }
})

app.register(fastifySwagger, {
  routePrefix: '/documentation',
  swagger: {
    info: {
      title: 'Test swagger',
      description: 'Testing the Fastify swagger API',
      version: '0.1.0'
    },
    host: 'localhost:3000',
    schemes: ['http'],
    consumes: ['application/json'],
    produces: ['application/json'],
  },
  uiConfig: {
    docExpansion: 'full',
    deepLinking: false
  },
  uiHooks: {
    onRequest: function (request, reply, next) { next() },
    preHandler: function (request, reply, next) { next() }
  },
  staticCSP: true,
  transformStaticCSP: (header) => header,
  exposeRoute: true
})

app.get('/', async function (req, reply) {
  return reply.send(true)
})

app.get('/socket.io/', (req, res) => {
  app.io.on('connection', (socket) => {
    var peer = board().connect()
    socket.on('rtc-signal', peer.process)
    peer.on('data', (data) => {
      socket.emit('rtc-signal', data)
    });
  });
})

app.listen({ port: 3000 }, (err, address) => {
  if (!err) console.info(`Server Started at ${address}`)
  else console.error(err)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions