подписки федерации apollo на узле 8.11.1

#node.js #graphql #graphql-subscriptions #apollo-federation

#node.js #graphql #graphql-подписки #apollo-федерация

Вопрос:

я новичок в федерации apollo. Я пытаюсь включить подписку, которая у меня есть на моем удаленном сервере (на другом хосте, написанном на aiohttp), в схему федерации. И при запуске моего узла проблем нет index.js но в документах нет подписки, и если я попробую в altair, то получу тот же результат. Пожалуйста, примите во внимание, что сама подписка полностью работоспособна, потому что я могу получить доступ к ней через Swart Web Socket client, и она получит мой счет. Чего мне не хватает и как это можно исправить. Заранее благодарю вас.

Вот моя подписка (написанная на python с помощью 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)

  

вот мой 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' amp;amp;
                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)
  

Ответ №1:

я забыл включить схему подписки в свой серверный сервер