如何在 Apollo 服务器中共享自定义 typeDef 和枚举?

How do I share custom typeDefs and enum in Apollo server?

假设我有两个typeDef,一个是用户,另一个是产品。在用户 typeDef 中,我有一个名为 logout 的突变,当调用 returns 时会显示一条消息。另一个 typeDef( product ) 有一个名为 add product 的函数,当再次调用时 returns 一条消息。我在两个 typeDef 中分别添加了消息 typeDef,但这会引发错误 There can only one type named \"Message\".\n\nField \"Message.message\" can only be defined once 。为了清楚起见,我也添加了屏幕截图。那么如何在两个 typeDef 之间共享消息 typeDef?我希望我已经解释了我的问题。

我创建了一个文件夹,并在该文件夹中创建了 message.js typeDef。我将这个文件包含在我的根 typeDef 中。这种方法解决了我跨 typeDef 共享 typeDef 的问题。