@graphity/restful
TypeScript icon, indicating that this package has built-in type declarations

0.6.0-alpha.1 • Public • Published

Graphity - RESTFul

Downloads Version License Typescript

How to use

Installation

npm install @graphity/restful --save

Simple Example

import { createExpressAdapter } from "@graphity/restful"
import { ApolloServer } from "apollo-server-express"
import bodyParser from "body-parser"

const schema = { ... } // GraphQLSchema 

const apollo = new ApolloServer({
  schema,
})

const app = express()

apollo.applyMiddleware({app})

app.use(bodyParser())
app.use(createExpressAdapter(schema, {
  endpoints: [
    {
      method: "GET",
      path: "/",
      query: (req) => ({
        document: parse(`query { version }`),
      })
    },
    {
      method: "POST",
      path: "/articles",
      query: (req) => ({
        document: parse(`mutation($title: String!, $contents: String) {
          article: createArticle(title: $title, contents: $contents) {
            id
            title
            contents
          }
        }`),
        values: {
          title: req.body.title,
          contents: req.body.contents,
        },
      })
    },
  ],
}))

app.listen(8080)

Licesnse

MIT

Package Sidebar

Install

npm i @graphity/restful

Weekly Downloads

1

Version

0.6.0-alpha.1

License

MIT

Unpacked Size

10.5 kB

Total Files

20

Last publish

Collaborators

  • wan2land