visual-studio-code - 如何正确声明无参数的 GraphQL 查询。

标签 visual-studio-code graphql lint

我正在使用 vs 代码 + graphql-cli用于验证和 linting 模式。在以下声明中(在 graphql 模式文件中):

type Query {
  users(): Int
}
users上面的声明被标记为 en 错误,但它不会给服务器带来任何问题(或警告)——它只是 vs 代码和 graphql lint将其报告为错误:
2:9 Syntax Error: Expected Name, found )  undefined

如果我向查询添加一个参数,例如:
type Query {
  users(n: Int): Int
}

那么vs code或者graphql-cli都没有报告问题。
如何正确声明没有参数的 graphql 查询。

最佳答案

您在架构中指定的查询就像特定类型上的任何其他字段一样(主要区别在于它们的类型链接到特定操作)。如果不想为特定字段声明任何参数,只需完全省略括号。查询和变更也是如此:

type Query {
  users: Int
}

从规范:

Fields are conceptually functions which return values, and occasionally accept arguments which alter their behavior. These arguments often map directly to function arguments within a GraphQL server’s implementation.



所以值得指出的是,任何类型的字段都可以有参数。例如,查询可能如下所示:
query UsersQuery {
  users {
    name
    posts (onlyNew: true) {
      title
    }
  }
}

关于visual-studio-code - 如何正确声明无参数的 GraphQL 查询。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52769993/

相关文章:

java - 安卓 Lint。是否可以通过命令行扫描 .java 类

Gitlab CI 环境 lint 语法不正确

android-studio - Flutter/Dart 自动完成功能适用于 VS Code,但不适用于 Android Studio

javascript - 为什么 createServer() 被认为不是函数?

node.js - "npm run"卡在 ts-loader (webpack)

graphql - 页面加载无需刷新,简洁且动态路由

javascript - GraphQL 大整数错误 : Int cannot represent non 32-bit signed integer value

ios - Apollo iOS swift 总是从本地缓存中获取 GraphQl

android - Android Lint 检查中的 "Namespace is not bound"

html - VScode : how-to change the color of HTML open and closing tag