• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

RisingStack/graffiti: ⚠️ DEVELOPMENT DISCONTINUED - Node.js GraphQL ORM

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

RisingStack/graffiti

开源软件地址(OpenSource Url):

https://github.com/RisingStack/graffiti

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

Notice: the development of the package is discontinued. Use it for educational purposes and hobby projects only.

graffiti

npm version Codeship Status for RisingStack/graffiti bitHound Overall Score Known Vulnerabilities

Currently the consumption of HTTP REST APIs dominate the client-side world, GraphQL aims to change this. This transition can be time-consuming - this is where graffiti comes into the picture.

We don't want to rewrite our application - no one wants that. graffiti provides an Express middleware, a Hapi plugin and a Koa middleware to convert your existing models into a GraphQL schema and exposes it over HTTP.

What is GraphQL?

GraphQL is a query language created by Facebook in 2012 which provides a common interface between the client and the server for data fetching and manipulations.

The client asks for various data from the GraphQL server via queries. The response format is described in the query and defined by the client instead of the server: they are called client‐specified queries.

For more info check out RisingStack's GraphQL tutorial.

Example server and queries

For a running example server and executable queries, check out our example repository and play with your GraphQL queries: graffiti-example

Adapters

Supported servers

Install

npm install @risingstack/graffiti --save

Usage

  1. run MongoDB
  2. register the middleware
  3. provide a schema (returned by an adapters getSchema method or your own GraphQLSchema instance)
  4. the GraphQL endpoint is available on /graphql

Express

import express from 'express';
import { json } from 'body-parser';
import graffiti from '@risingstack/graffiti';
import { getSchema } from '@risingstack/graffiti-mongoose';

import Cat from './models/Cat';
import User from './models/User';

const app = express();

// parse body as json
app.use(json());

app.use(graffiti.express({
  schema: getSchema([User, Cat]),
  context: {} // custom context
}));

app.listen(3000);

Hapi

import { Server } from 'hapi';
import graffiti from '@risingstack/graffiti';
import { getSchema } from '@risingstack/graffiti-mongoose';

const server = new Server();
server.connection({ port: 3000 });

server.register({
  register: graffiti.hapi,
  options: {
    schema: getSchema([User, Cat]),
    context: {}, // custom context 
    config: {} // config parameter for hapi graphql route
  }
}, function (err) {
  if (err) {
    console.error('Failed to load plugin:', err);
  }

  server.start(function () {
      console.log('Server running at:', server.info.uri);
  });
});

Koa

import koa from 'koa';
import parser from 'koa-bodyparser';
import graffiti from '@risingstack/graffiti';
import { getSchema } from '@risingstack/graffiti-mongoose';

import Cat from './models/Cat';
import User from './models/User';

const app = koa();

app.use(parser());

app.use(graffiti.koa({
  schema: getSchema([User, Cat]),
  context: {} // custom context
}));

app.listen(3000);

Options

  • schema: a GraphQLSchema instance. You can use an adapters getSchema method, or provide your own schema. (required)
  • graphiql: may present GraphiQL when loaded directly from a browser. (default: true)
  • context: custom GraphQL context object. (default: {})

Test

npm test



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap