首页 > 解决方案 > 未调用某些字段的 GraphQL 解析器

问题描述

我为学习目的编写了简单的 GraphQL 模式和解析器,但我无法理解为什么我的代码按预期工作的原因。我将 Prisma 用于 ORM,并用于编写express-graphqlAPI graphql-import

type User {
  id: ID!
  name: String!
}

type Link {
  id: ID!
  url: String!
  user: User!
}

type Query {
  links(id: ID!): [Link!]!
}
// resolvers
const links = async (root, args, ctx) => {
  const links = await ctx.prisma.links({
    where: {
      user {
        id: args.id
      }
    }
  }
}
// resolver for `Link` type
const user = async (root, args, ctx) => {
  const user = await ctx.prisma.link({ id: parent.id }).user()
  return user
}

// omitted field resolver for `url` and `id`
module.exports = {
  user
}

使用这些代码,我希望在查询时得到id, url,user字段,但是当我发送查询时links,它会返回字段。这意味着,如果我在服务器端签入,则根本不会调用字段解析器。这有什么问题?nulluseruser

标签: graphqlprismaexpress-graphql

解决方案


推荐阅读