1

i'm new with apollo federation. I try to include subscritption which i have on my remote server (on other host written on aiohttp) to federation schema. And there are no issue when i start my node index.js but there is no subscription in docs and if i try in altair the same result. Please take in to account that the subscription itself is fully workable because i can reach it via Swart Web Socket client and it recieve me my count. What i'm missing and how it could be fixed. Thank you in advance.

Here is my subscription(written on python by aiohttp):

class Subscriptions(graphene.ObjectType):
    count_seconds_one = graphene.Float(up_to=graphene.Int())

    @async_generator
    async def resolve_count_seconds_one(self, info, up_to):
        for i in range(up_to):
            await yield_(i)
            await asyncio.sleep(1.)
        await yield_(i)

here is my index.js

const { ApolloServer, gql, mergeSchemas, introspectSchema, makeRemoteExecutableSchema } = require('apollo-server')
const { HttpLink } = require('apollo-link-http')
const fetch = require('node-fetch')
const { WebSocketLink } = require('apollo-link-ws')
const { split } = require('apollo-link')
const { getMainDefinition } = require('apollo-utilities')
const { SubscriptionClient } = require('subscriptions-transport-ws')
const ws = require('ws')

const resolvers = {}


async function getRemoteSchema({ uri, subscriptionsUri }) {
    const httpLink = new HttpLink({ uri, fetch })

    const client = new SubscriptionClient(subscriptionsUri, { reconnect: true }, ws)
    const wsLink = new WebSocketLink(client)

    const link = split(
        operation => {
            const definition = getMainDefinition(operation.query)
            console.log(definition)
            return (
                definition.kind === 'OperationDefinition' &&
                definition.operation === 'subscription'
            )
        },
        wsLink,  // <-- Use this if above function returns true
        httpLink // <-- Use this if above function returns false
    )

    const schema = await introspectSchema(link)
    const executableSchema = makeRemoteExecutableSchema({ schema, link })

    return executableSchema
}


async function run() {

    //
    const remoteSchema1 = await getRemoteSchema({ uri: 'http://127.0.0.1:8000',
        subscriptionsUri: 'ws://localhost:8005/subscriptions'
    })

    const remoteSchema3 = await getRemoteSchema({
        uri: 'http://localhost:8005/graphql',
        subscriptionsUri: 'ws://localhost:8005/subscriptions'
    })

    const resolvers = {}

    const schema = mergeSchemas({
        schemas: [
            remoteSchema1,

            remoteSchema3,

        ],
    })


    const server = new ApolloServer({ schema })

    server.listen().then(({ url, subscriptionsUrl }) => {
        console.log(` Server ready at ${url}`);
        console.log(` Subscriptions ready at ${subscriptionsUrl}`);
    })
}

run().catch(console.log)
dmitriy_one
  • 477
  • 1
  • 5
  • 16

1 Answers1

0

i forgot to include subscription schema on my backend

dmitriy_one
  • 477
  • 1
  • 5
  • 16