1. const express = require("express");
    2. const { buildSchema } = require("graphql");
    3. const { graphqlHTTP } = require("express-graphql");
    4. const schema = buildSchema(`
    5. type Account {
    6. name: String,
    7. age: Int,
    8. sex: String,
    9. department: String
    10. }
    11. type Query {
    12. hello: String,
    13. userName: String,
    14. age: Int,
    15. account: Account
    16. }
    17. `);
    18. const root = {
    19. hello: () => "Hello world!",
    20. userName: () => "wcd",
    21. age: () => 25,
    22. account: () => {
    23. return {
    24. name: "wcd",
    25. age: 25,
    26. sex: "boy",
    27. department: "technical division",
    28. };
    29. },
    30. };
    31. const app = express();
    32. app.use(
    33. "/graphql",
    34. graphqlHTTP({
    35. schema: schema,
    36. rootValue: root,
    37. graphiql: true,
    38. })
    39. );
    40. app.listen(3000, () => console.log("Now browse to localhost:3000/graphql"));