GraphQL入门

2022-03-24 10:41:24 浏览数 (2)

代码语言: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

0 人点赞