sirsavary / fastify-graphql

Run an Apollo Server on Fastify.
https://www.npmjs.com/package/fastify-graphql
MIT License
24 stars 5 forks source link

Can I use with Graphql subscription ? #9

Closed annibuliful closed 4 years ago

Extarys commented 6 years ago
import { SubscriptionServer } from 'subscriptions-transport-ws'
import { execute, subscribe } from 'graphql'
var httpSrv = fastify.listen(3002, err => {
    if (err) throw err;
    console.log('Server listenting on localhost:', fastify.server.address().port);
});
const graphSrv = new SubscriptionServer(
    {
        execute,
        subscribe,
        schemaGraph
    },
    {
        server: httpSrv,
        path: '/graphql'
    }
)

I have some schema issues, but that'S the code I have right now. Hope it works.

annibuliful commented 6 years ago

Thank you sir

Extarys commented 6 years ago

I had to change schemaGraph to schema: schemaGraph though (I forgot to change it in my first reply), hope you figured it out! :smile:

annibuliful commented 6 years ago

Thank you sir

sirsavary commented 6 years ago

Apologies for not seeing this sooner! Thank you @Extarys for your example, I might document this in the README.

Extarys commented 6 years ago

No problem, my pleasure

annibuliful commented 6 years ago
screen shot 2561-05-12 at 00 03 46 screen shot 2561-05-12 at 00 04 29

it doesn't work . I don't know what are the problems

annibuliful commented 6 years ago

I fix it by changing httpServer to fastify.server it's not error but Subscription doesn't work. Why?

annibuliful commented 6 years ago
screen shot 2561-06-03 at 05 20 48

I'm not sure that [object object] is error or not ?

annibuliful commented 6 years ago

https://github.com/n3ologism/music-fastify/tree/backend/backend/src

This is my repository

odlainepre commented 4 years ago

@lagmanzaza tnx, its work for me fastify.server

import { execute, subscribe } from 'graphql'
import { SubscriptionServer } from 'subscriptions-transport-ws';

import { schema } from "./api/schema"

const fastify = require('fastify')({
    logger: false
})

// This `listen` method launches a web-server
fastify.listen(3000, (err, address) => {
    if (err) throw err
    console.log('\x1b[35m', `🚀 Server ready at http://localhost:3000/graphql`)
    console.log("\x1b[35m", `🚀 Subscription server ws://localhost:3000/graphql`)
})

new SubscriptionServer(
    {
        schema,
        execute,
        subscribe,
    },
    {
        server: fastify.server,
        path: '/graphql',
    },
);
annibuliful commented 4 years ago

@nikitamarcius Actually, You can use Apollo server instead

odlainepre commented 4 years ago

@lagmanzaza nope. Tried first, HTTP endpont works, but subscriptions no handshake error. Test with Koa and Fastify. Works only with HTTP native module

Better Graphql + Fastify + subscriptions.