Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.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,我有一个graphql服务器,我正在尝试实现一个查询,该查询将使用节点列表更新客户端 在nodes.js中,我有: export const nodes = { "nodes": [ {id: 1, "name": 'building_1', "hasStrobe": true}, {id: 2, "name": 'building_2', "hasStrobe": false}, {id: 3, "name": 'building_3', "hasStrobe":

我有一个graphql服务器,我正在尝试实现一个查询,该查询将使用节点列表更新客户端

在nodes.js中,我有:

export const nodes = {
  "nodes": [
    {id: 1, "name": 'building_1', "hasStrobe": true},
    {id: 2, "name": 'building_2', "hasStrobe": false},
    {id: 3, "name": 'building_3', "hasStrobe": true}
  ]
}
我在schema.js中的查询如下:

const Query = new GraphQLObjectType({
  name: 'Query',
  description: 'Root query object',
  fields() {
    return {
      message: {
        type: Message,
        resolve() {
          return getMessage();
        },
      },
      system: {
        type: System,
        resolve() {
          return getSystemInfo();
        },
      },
      nodes: {
        type: Nodes,
        resolve() {
          //console.log(nodes.nodes)
          return nodes.nodes;
        }
      },

      // alert: {
      //   type: Alert,
      //   resolve() {
      //     return 'poke';
      //   }
      // }
    };
  },
});
const Nodes = new GraphQLObjectType({
  name: 'Nodes',
  description: 'List of zone nodes and their capabilities.',
  fields() {
    return {
      nodes: {
        type: GraphQLString,
        resolve(msg) {
          console.log(msg)
          return msg;
        }
      },
    }
  }
});
我的节点类型如下:

const Query = new GraphQLObjectType({
  name: 'Query',
  description: 'Root query object',
  fields() {
    return {
      message: {
        type: Message,
        resolve() {
          return getMessage();
        },
      },
      system: {
        type: System,
        resolve() {
          return getSystemInfo();
        },
      },
      nodes: {
        type: Nodes,
        resolve() {
          //console.log(nodes.nodes)
          return nodes.nodes;
        }
      },

      // alert: {
      //   type: Alert,
      //   resolve() {
      //     return 'poke';
      //   }
      // }
    };
  },
});
const Nodes = new GraphQLObjectType({
  name: 'Nodes',
  description: 'List of zone nodes and their capabilities.',
  fields() {
    return {
      nodes: {
        type: GraphQLString,
        resolve(msg) {
          console.log(msg)
          return msg;
        }
      },
    }
  }
});
运行查询时,它会将nodes.nodes正确记录到控制台:

[ { id: 1, name: 'building_1', hasStrobe: true },
  { id: 2, name: 'building_2', hasStrobe: false },
  { id: 3, name: 'building_3', hasStrobe: true } ]
而查询输出为:

{
  "data": {
    "system": {
      "uname": "4.11.5-2-ck-haswell\n",
      "time": "Thu Jun 22 2017 17:39:29 GMT-0500 (CDT)"
    },
    "nodes": {
      "nodes": "[object Object],[object Object],[object Object]"
    }
  }
}

我不确定如何处理数据数组以输出节点。

作为旁注,ReactQL的graphql实现非常棒。作为旁注,ReactQL的graphql实现非常棒。