伺服器安裝實施

GraphQL.js

GraphQL.jsGraphQL 的 JavaScript 參考實現。你可以通過 npm 安裝它:

  • 如果你還沒有在專案中初始化 npm:npm init
  • 從 npm:npm install --save graphql 安裝 GraphQL.js

示例伺服器

var { graphql, buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: String
  }
`);

// The root provides a resolver function for each API endpoint
var root = {
  hello: () => {
    return 'Hello world!';
  },
};

// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then((response) => {
  console.log(response);
});

伺服器中介軟體替代品