zzz's notebooks

  • fauna - /zzz/fauna
    Last edited 4 years ago
    const express = require("express") const app = express() const faunadb = require("faunadb") const q = faunadb.query const client = new faunadb.Client({ secret: process.env.FAUNA_SECRET }) app.get("/", (req, res) => { client.ping() .then(ret => res.send(JSON.stringify(ret, null, 2))) .catch(err => res.send(err.message)) }) app.get('/fauna', (req, res) => { client.query( q.Paginate(q.Match(q.Index("all_customers"))) ) .then(ret => res.send(ret.data[0])) .catch(err => res.send(err.message)) }) app.listen(8080)
  • graphql - /zzz/graphql
    Last edited 4 years ago
    var express = require("@runkit/runkit/express-endpoint/1.0.0"); var graphqlHTTP = require("express-graphql"); var { buildSchema } = require("graphql"); //定义schema var schema = buildSchema(` type User { name: String sex: String intro: String } type Query { user:User } `); //定义服务端数据 var root = { user: { name: "UserName", sex: "Man", intro: "UserName is me." } }; var app = express(exports); app.use("/", graphqlHTTP({ schema: schema, rootValue: root, graphiql: true //启用GraphiQL }) ); app.listen(8080, () => console.log("localhost:8080/graphql"));