Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphql 如何访问传递给子查询的变量_Graphql - Fatal编程技术网

Graphql 如何访问传递给子查询的变量

Graphql 如何访问传递给子查询的变量,graphql,Graphql,我希望能够向子查询添加参数,但我不知道如何让它工作 我正试图用一个查看器对象编写一个模式,该对象包含我的查询,以便返回边/节点。我想我遗漏了一些关于解析器的基本知识,但是,在谷歌搜索了很多之后,我仍然不明白 我的模式如下所示(仅相关位): LinkConnection是您所期望的,它有一个edges属性,即节点列表等 我使用的是Prisma,分解器如下所示: const allLinks = async (parent, args, context, info) => { const

我希望能够向子查询添加参数,但我不知道如何让它工作

我正试图用一个查看器对象编写一个模式,该对象包含我的查询,以便返回边/节点。我想我遗漏了一些关于解析器的基本知识,但是,在谷歌搜索了很多之后,我仍然不明白

我的模式如下所示(仅相关位):

LinkConnection是您所期望的,它有一个edges属性,即节点列表等

我使用的是Prisma,分解器如下所示:

const allLinks = async (parent, args, context, info) => {
  const links = await context.prisma.linksConnection({
    first: args.first,
    orderBy: args.orderBy,
  })
  const count = await context.prisma
    .linksConnection()
    .aggregate()
    .count()
  return {
    pageInfo: links.pageInfo,
    edges: links.edges,
    count,
  }
}

export const viewer = async (parent, args, context, info) => {
  const links = await allLinks(parent, args, context, info)
  return { allLinks: links }
}
如果我做这个查询:

query {
  viewer {
    allLinks(first: 1, orderBy:createdAt_DESC) {
      edges {
        node {
          id
        }
      }
      count
    }
  }
}
然后它运行时没有实际出错,但它返回所有链接,而不是一个链接,我使用了console.logging,第一个和orderBy参数似乎没有实际执行任何操作

有人能帮我解释一下我是如何构造解析器的,这样这些参数就能真正起作用了吗?看来这应该是显而易见的

query {
  viewer {
    allLinks(first: 1, orderBy:createdAt_DESC) {
      edges {
        node {
          id
        }
      }
      count
    }
  }
}