Apollo federation ( ошибка в gql - Unknown directive "key" )

Изучаю apollo federation пример из документации webstorm ругается ( хотя код рабочий ), что Unknown directive "key" / Unknown argument "fields" / 'Query' extension type [@13:2] tried to redefine field 'astronaut' [@14:3] / 'Astronaut' type [@9:2] tried to redefine existing 'Astronaut' type [@7:1]

const typeDefs = gql`
    type Astronaut @key(fields: "id") {
        id: ID!
        name: String
    }
    extend type Query {
        astronaut(id: ID!): Astronaut
        astronauts: [Astronaut]
    }

схему делал через расшширение webstorm js graphql

# This file was generated based on ".graphqlconfig". Do not edit manually.

schema {
    query: Query
}

type Astronaut {
    id: ID!
    missions: [Mission]
    name: String
}

type Mission {
    crew: [Astronaut]
    designation: String!
    endDate: String
    id: ID!
    startDate: String
}

type Query {
    astronaut(id: ID!): Astronaut
    astronauts: [Astronaut]
    mission(id: ID!): Mission
    missions: [Mission]
}

gataway

import { ApolloServer } from 'apollo-server'
import { ApolloGateway } from '@apollo/gateway'

const port = 4000

const gateway = new ApolloGateway({
    serviceList: [
        { name: 'astronauts', url: 'http://localhost:4001' },
        { name: 'missions', url: 'http://localhost:4002' }
    ]
})

const server = new ApolloServer({
    gateway,
    subscriptions: false
})

server.listen({ port }).then(({ url }) => {
    console.log(`Server ready at ${url}`)
})

service

import { ApolloServer, gql } from 'apollo-server'
import { buildFederatedSchema } from '@apollo/federation'

import fetch from 'node-fetch'

const port = 4001
const apiUrl = 'http://localhost:3000'
const typeDefs = gql`
    type Astronaut @key(fields: "id") {
        id: ID!
        name: String
    }
    extend type Query {
        astronaut(id: ID!): Astronaut
        astronauts: [Astronaut]
    }
`

const resolvers = {
    Astronaut: {
        __resolveReference(ref:any) {
            return fetch(`${apiUrl}/astronauts/${ref.id}`).then((res) => res.json())
        }
    },
    Query: {
        astronaut(_:any, { id }:any) {
            return fetch(`${apiUrl}/astronauts/${id}`).then((res) => res.json())
        },
        astronauts() {
            return fetch(`${apiUrl}/astronauts`).then((res) => res.json())
        }
    }
}

const server = new ApolloServer({
    schema: buildFederatedSchema([{ typeDefs, resolvers }])
})

server.listen({ port }).then(({ url }) => {
    console.log(`Astronauts service ready at ${url}`)
})


Ответы (0 шт):