【问题标题】:graphql modules extend type defs by nestinggraphql 模块通过嵌套扩展类型定义
【发布时间】:2019-12-29 05:13:05
【问题描述】:

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

我有以下类型定义:

UserProfile 的 typeDef:

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]
  }
`;

这里是学校类型定义:

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
    }
  }
}

它抱怨它不能:

“无法查询类型 \"UserProfile\" 上的字段 \"schoolInfo\"。

此架构中缺少什么?

【问题讨论】:

    标签: graphql apollo graphql-js apollo-server


    【解决方案1】:

    您是否已导入所有模块?

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

    否则他们将无法互动。

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 2020-03-03
      • 2022-01-03
      • 2010-12-13
      • 2023-01-10
      • 1970-01-01
      • 2019-02-14
      • 2020-02-28
      • 2020-10-30
      相关资源
      最近更新 更多