Skip to content

Latest commit

 

History

History

restful

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Graphity Extensions - RESTFul

Downloads Version License Typescript
dependencies Status

Installation

npm install @graphity-extensions/restful --save

Usage

Simple Example

import { createExpressAdapter } from "@graphity-extensions/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)