代码语言:javascript复制
mkdir graphqljs
cd graphqljs
npm init
npm install --save graphql
touch hello.js
编辑hello.js
代码语言:javascript复制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);
})
运行代码
代码语言:javascript复制node hello