Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast-map breaks mercurius #251

Open
VirtuousDeath opened this issue Jul 1, 2023 · 0 comments
Open

fast-map breaks mercurius #251

VirtuousDeath opened this issue Jul 1, 2023 · 0 comments

Comments

@VirtuousDeath
Copy link

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)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant