montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 185 forks source link

fast-map breaks mercurius #251

Open VirtuousDeath opened 1 year ago

VirtuousDeath commented 1 year ago

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)
})