【发布时间】:2018-04-11 19:22:27
【问题描述】:
我正在尝试将 graphql 用于基于 id 的 GET 请求之一。代码如下:
const { graphql, buildSchema } = require('graphql');
EmployeeService.prototype.getEmployee = function() {
// Construct a schema
const schema = buildSchema(`
type Query {
employee(id="12345") {
id
items {
id
name
}
}
}
`);
// The root provides a resolver function
let root = {
employee: () => id
};
// Run the GraphQL query
graphql(schema, '{ employee }', root).then((response) => {
console.log(response);
});
};
尝试遵循http://graphql.org/graphql-js/ 上的文档。
我收到 GraphQL 错误:"Syntax Error GraphQL request (3:19) Expected :, found =↵↵2: type Query {↵3: employee (id="12345") {↵ ^↵4: id↵"
请指教。
【问题讨论】:
标签: graphql angularjs node.js graphql