我正在尝试使用Apollo Federation将一种模式的类型转换为另一种模式。
我在Lerna的monorepo项目中有2个软件包,分别为:receivers
和transaction
。
在receivers
包中,我将其保存在index.ts
文件中:
import { buildFederatedSchema } from '@apollo/federation';
import { ApolloServer } from 'apollo-server-lambda';
import getMyTransactions from './resolvers/getMyTransactions';
import typeDefs from './receivers.gql';
const resolvers = {
Query: {
getMyTransactions
},
};
const server = new ApolloServer({
schema: buildFederatedSchema([{ typeDefs, resolvers }]),
context: ({ event }) => ({
authorizer: event.requestContext.authorizer
}),
});
现在,我对这两个软件包的架构都是:
// receivers.gql
extend type Transaction @key(fields: "id") {
id: ID! @external
}
type Query {
getMyTransactions: [Transaction!]!
}
// transaction.gql
type Transaction @key(fields: "id") {
id: ID!
createdAt: String!
}
我正在Graphql Playground上执行此查询以获取getMyTransactions查询:
query getMyTransactions{
getMyTransactions{
status
id
createdAt
}
}
但是我从Graphql得到这个错误:
"message": "Cannot query field \"createdAt\" on type \"Transaction\".",
我做错了什么?我应该找什么?