Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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
Node.js 理解GraphQl查询_Node.js_Graphql_Apollo Server - Fatal编程技术网

Node.js 理解GraphQl查询

Node.js 理解GraphQl查询,node.js,graphql,apollo-server,Node.js,Graphql,Apollo Server,我试图学习和理解GraphQl 为了做到这一点,我去了 从他们的博客,在我们的Studio.js文件中,考虑到我们有一些类似的东西。 onst { gql } = require('apollo-server'); const typeDefs = gql` type Query { launches: [Launch]! launch(id: ID!): Launch me: User } type Launch { id: ID! site: String mis

我试图学习和理解GraphQl

为了做到这一点,我去了

从他们的博客,在我们的Studio.js文件中,考虑到我们有一些类似的东西。
onst { gql } = require('apollo-server');
const typeDefs = gql`

type Query {
  launches: [Launch]!
  launch(id: ID!): Launch
  me: User
}

type Launch {
  id: ID!
  site: String
  mission: Mission
  rocket: Rocket
  isBooked: Boolean!
}
module.exports = typeDefs;
现在在我们可以查询的工具中(比如graphiqL),在他们的示例中,他们在查询中做了类似的事情

onst { gql } = require('apollo-server');
const typeDefs = gql`

type Query {
  launches: [Launch]!
  launch(id: ID!): Launch
  me: User
}

type Launch {
  id: ID!
  site: String
  mission: Mission
  rocket: Rocket
  isBooked: Boolean!
}
module.exports = typeDefs;
{
  launch(id: 1) {
    site
  }
}
我不确定-这里是关于我们的
站点
在上面的graphiqL对象中的位置,以及我们如何编写它(因为在我们的查询中,launch需要返回类型if launch,并且只需要id
launch(id:id!):launch

为什么这个查询无效

{
  launch(id: 1) 
}

您需要为复杂类型指定字段。例如(“并且只需要id”)

(id:1)
中的内容是查询的输入(类似于函数的参数)。但是你仍然需要明确你想要什么

UPD。需要澄清的是,相同的规则适用于嵌套的复杂类型。例如,如果你想得到发射火箭,你不能简单地做到

{
  launch(id: 1) {
    id
    rocket # does not work
  }
}
您需要指定所需的火箭场

{
  launch(id: 1) {
    id
    rocket {
      id
    }
  }
}