graphql 模块通过嵌套扩展类型定义

graphql modules extend type defs by nesting

我正在使用 apollo 模块,并且我有多个模块: 用户资料, 学校, 项目

我有以下类型定义:

用户配置文件的类型定义:

export const typeDefs = gql`
  extend type Query {
    getUserProfile(uuid: String!): UserProfile
  }

  type UserProfile {
    id: ID!
    email: String,
    uuid: String,
    firstName: String,
    lastName: String,
    school: String
  }

  extend type Project {
    userInfo: UserProfile
  }
`;

为项目键入 def:

export const typeDefs = gql`
  extend type Query {
    getProject(uuid: String!): Project
  }

  type Project {
    _id: ID!
    user: String,
    name: String,
    uuid: String
  }

  extend type UserProfile {
    userProjects: [Project]
  }
`;

这里是学校类型 def:

export const typeDefs = gql`
  extend type Query {
    getSchool(uuid: String!): School
  }

  type School {
    _id: ID!
    uuid: String,
    name: String,
  }

  extend type UserProfile {
    schoolInfo: School
  }
`;

现在,如果我执行以下查询:

query {
  getProject(uuid: "a9e2f2ea") {
    name
    uuid
    ownerInfo {
      email
      gender
    }
    userInfo {
      lastName
      school
      schoolInfo
    }
  }
}

它抱怨它不能:

"Cannot query field \"schoolInfo\" on type \"UserProfile\".

此架构中缺少什么?

你导入所有的模块了吗?

const server = new ApolloServer({
        modules: [
            require('./modules/userProfile'),
            require('./modules/project'),
            require('./modules/school'),
        ],
        context: ...
});

否则无法互动