graphql where 子句 Angular Apollo Client

标签 graphql apollo-client

使用角阿波罗客户端。

我正在尝试使用 where 子句

getPage(slug: string) {
    return this.apollo
      .query({
        variables: {
          slug: slug
        },
        query: gql`
          query pages(where: { $slug: slug }) {
            pages (slug: $slug) {
              slug,
              title,
              content,
              cover {
                name,
                url,
              },
              createdAt,
              updatedAt
            }
          }
        `
      });
  }

我在浏览器控制台中收到此错误:
message: "Syntax Error: Expected $, found Name "where""

最佳答案

好吧,我想通了。

getPage(slug: string) {
    return this.apollo
      .query({
        variables: {
          slug: slug
        },
        query: gql`
          query pages ($slug: String) {
            pages (where: { slug: $slug }) {
              slug,
              title,
              content,
              cover {
                name,
                url,
              },
              createdAt,
              updatedAt
            }
          }
        `
      });
  }

关于graphql where 子句 Angular Apollo Client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54215349/

相关文章:

amazon-cognito - 如何修复来自 Apollo 客户端的 Malformed authentication header 错误

OData 与 GraphQL

.net-core - HotChocolate带有Authorize属性,如何获取当前登录的用户?

graphql - 为什么 GraphQL 不接受这种标量参数类型,而是提示 "argument type must be Input Type but got: undefined"?

javascript - 如何修复 graphql 突变类型名称错误

android - Apollo GraphQL for Android 中的重复对象类型

kotlin - apollo 协程是否支持在默认 IO 调度程序上执行后台操作

graphql - 将 ImageSharp 作为字段添加到 MarkdownRemark 节点(不是 frontmatter)

javascript - 删除突变返回 null

javascript - 无法从 ApolloClient 中的 localStorage 检索更新的 token