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