mkdir graphqljs
cd graphqljs
npm init
npm install --save graphql
touch hello.js
编辑hello.js
var {
graphql,
buildSchema
} = require('graphql');
var schema = buildSchema(`
type Query{
hello:String
}`);
var root = {
hello: () => 'Hello world!'
};
graphql(schema, '{hello}', root).then((response) => {
console.log(response);
})
运行代码
node hello
来源:oschina
链接:https://my.oschina.net/u/579683/blog/1845114