graphjin

graphjin

将GraphQL查询自动转换为高效SQL的创新ORM工具

GraphJin是一款创新ORM工具,可将GraphQL查询自动转换为高效SQL。该工具支持多种数据库,内置安全机制,并提供详细文档和示例代码。GraphJin适用于Node.js和Go环境,既可作为独立服务,也可作为库集成使用。开发者使用GraphJin能快速构建完整的API功能,显著提升开发效率。

GraphJinORMGraphQLSQLAPI开发Github开源项目

GraphJin, A New Kind of ORM

Apache 2.0 NPM Package Docker Pulls Discord Chat GoDoc GoReport

Build APIs in 5 minutes not weeks

Just use a simple GraphQL query to define your API and GraphJin automagically converts it into SQL and fetches the data you need. Build your backend APIs 100X faster. Works with NodeJS and GO. Supports several databases, Postgres, MySQL, Yugabyte, AWS Aurora/RDS and Google Cloud SQL

The following GraphQL query fetches a list of products, their owners, and other category information, including a cursor for retrieving more products. GraphJin will do auto-discovery of your database schema and relationships and generate the most efficient single SQL query to fetch all this data including a cursor to fetch the next 20 item. You don't have to do a single thing besides write the GraphQL query.

query getProducts { products( # returns only 20 items limit: 20 # orders the response items by highest price order_by: { price: desc } # only items with a price >= 20 and < 50 are returned where: { price: { and: { greater_or_equals: 20, lt: 50 } } } ) { id name price # also fetch the owner of the product owner { full_name picture: avatar email # and the categories the owner has products under category_counts(limit: 3) { count category { name } } } # and the categories of the product itself category(limit: 3) { id name } } # also return a cursor that we can use to fetch the next # batch of products products_cursor }

Note: The corresponding SQL for creating the table (POSTGRES)

CREATE TABLE products ( id SERIAL NOT NULL, name TEXT NOT NULL, price INTEGER NOT NULL, owner_id INTEGER NOT NULL, category_id INTEGER NOT NULL, PRIMARY KEY(id) );

Secure out of the box

In production all queries are always read from locally saved copies not from what the client sends hence clients cannot modify the query. This makes GraphJin very secure as its similar to building APIs by hand. The idea that GraphQL means that clients can change the query as they wish does not apply to GraphJin

Great Documentation

Detailed docs on GraphQL syntax, usecases, JS and GO code examples and it's actively updated.

Docs

Example Code

Use with NodeJS

GraphJin allows you to use GraphQL and the full power of GraphJin to access to create instant APIs without writing and maintaining lines and lines of database code. GraphJin NodeJS currently only supports Postgres compatible databases working on adding MySQL support as well. Example app in /examples/nodejs

npm install graphjin
import graphjin from "graphjin"; import express from "express"; import http from "http"; import pg from "pg"; const { Client } = pg; const db = new Client({ host: "localhost", port: 5432, user: "postgres", password: "postgres", database: "appdb-development", }); await db.connect(); // config can either be a file (eg. `dev.yml`) or an object // const config = { production: true, default_limit: 50 }; var gj = await graphjin("./config", "dev.yml", db); var app = express(); var server = http.createServer(app); // subscriptions allow you to have a callback function triggerd // automatically when data in your database changes const res1 = await gj.subscribe( "subscription getUpdatedUser { users(id: $userID) { id email } }", null, { userID: 2 } ); res1.data(function (res) { console.log(">", res.data()); }); // queries allow you to use graphql to query and update your database app.get("/", async function (req, resp) { const res2 = await gj.query( "query getUser { users(id: $id) { id email } }", { id: 1 }, { userID: 1 } ); resp.send(res2.data()); }); server.listen(3000); console.log("Express server started on port %s", server.address().port);

Use with GO

You can use GraphJin as a library within your own code. The serv package exposes the entirely GraphJin standlone service as a library while the core package exposes just the GraphJin compiler. The Go docs are filled with examples on how to use GraphJin within your own apps as a sort of alternative to using ORM packages. GraphJin allows you to use GraphQL and the full power of GraphJin to access your data instead of a limiting ORM.

Use GraphJin Core

go get github.com/dosco/graphjin/core/v3
package main import ( "context" "database/sql" "log" "net/http" "github.com/dosco/graphjin/core" "github.com/go-chi/chi/v5" _ "github.com/jackc/pgx/v5/stdlib" ) func main() { db, err := sql.Open("pgx", "postgres://postgres:@localhost:5432/exampledb?sslmode=disable") if err != nil { log.Fatal(err) } gj, err := core.NewGraphJin(nil, db) if err != nil { log.Fatal(err) } query := ` query getPosts { posts { id title } posts_cursor }` router := chi.NewRouter() router.Get("/", func(w http.ResponseWriter, request *http.Request) { context := context.WithValue(request.Context(), core.UserIDKey, 1) res, err := gj.GraphQL(context, query, nil, nil) if err != nil { log.Fatal(err) return } w.Write(res.Data) }) log.Println("Go server started on port 3000") http.ListenAndServe(":3000", router) }

Use GraphJin Service

import ( "github.com/dosco/graphjin/serv/v2" ) gj, err := serv.NewGraphJinService(conf, opt...) if err != nil { return err } if err := gj.Start(); err != nil { return err } // if err := gj.Attach(chiRouter); err != nil { // return err // }

Standalone Service

Quick install

# Mac (Homebrew)
brew install dosco/graphjin/graphjin

# Ubuntu (Snap)
sudo snap install --classic graphjin

Debian and Redhat (releases) Download the .deb or .rpm from the releases page and install with dpkg -i and rpm -i respectively.

Quickly create and deploy new apps

graphjin new <app_name>

Instantly deploy new versions

# Deploy a new config graphjin deploy --host=https://your-server.com --secret="your-secret-key" # Rollback the last deployment graphjin deploy rollback --host=https://your-server.com --secret="your-secret-key"

Secrets Management

# Secure save secrets like database passwords and JWT secret keys graphjin secrets

Database Management

# Create, Migrate and Seed your database graphjin db

Built in Web-UI to help craft GraphQL queries

graphjin-screenshot-final

Support the Project

GraphJin is an open source project made possible by the support of awesome backers. It has collectively saved teams 1000's of hours dev. time and allowing them to focus on their product and be 100x more productive. If your team uses it please consider becoming a sponsor.

<div float="left"> <a href="https://42papers.com"> <img src="https://user-images.githubusercontent.com/832235/135753560-39e34be6-5734-440a-98e7-f7e160c2efb5.png" width="75" target="_blank"> </a> <a href="https://www.exo.com.ar/"> <img src="https://user-images.githubusercontent.com/832235/112428182-259def80-8d11-11eb-88b8-ccef9206b535.png" width="100" target="_blank"> </a> </div>

About GraphJin

After working on several products through my career I found that we spend way too much time on building API backends. Most APIs also need constant updating, and this costs time and money.

It's always the same thing, figure out what the UI needs then build an endpoint for it. Most API code involves struggling with an ORM to query a database and mangle the data into a shape that the UI expects to see.

I didn't want to write this code anymore, I wanted the computer to do it. Enter GraphQL, to me it sounded great, but it still required me to write all the same database query code.

Having worked with compilers before I saw this as a compiler problem. Why not build a compiler that converts GraphQL to highly efficient SQL.

This compiler is what sits at the heart of GraphJin, with layers of useful functionality around it like authentication, remote joins, rails integration, database migrations, and everything else needed for you to build production-ready apps with it.

Better APIs Faster!

Lets take for example a simple blog app. You'll probably need the following APIs user management, posts, comments, votes. Each of these areas need apis for listing, creating, updating, deleting. Off the top of my head thats like 12 APIs if not more. This is just for managing things for rendering the blog posts, home page, profile page you probably need many more view apis that fetch a whole bunch of things at the same time. This is a lot and we're still talking something simple like a basic blogging app. All these APIs have to be coded up by someone and then the code maintained, updated, made secure, fast, etc. We are talking weeks to months of work if not more. Also remember your mobile and web developers have to wait around till this is all done.

With GraphJin your web and mobile developers can start building instantly. All they have to do is just build the GraphQL queries they need and GraphJin fetches the data. Nothing to maintain no backend API code, its secure, lighting fast and has tons of useful features like subscriptions, rate limiting, etc built-in. With GraphJin your building APIs in minutes not days.

Highlevel

  • Works with Postgres, MySQL8, YugabyteDB
  • Also works with Amazon Aurora/RDS and Google Cloud SQL
  • Supports REST, GraphQL and Websocket APIs

More Features

  • Complex nested queries and mutations
  • Realtime updates with subscriptions
  • Add custom business logic in Javascript
  • Build infinite scroll, feeds, nested comments, etc
  • Add data validations on insert or update
  • Auto learns database tables and relationships
  • Role and Attribute-based access control
  • Cursor-based efficient pagination
  • Full-text search and aggregations
  • Automatic persisted queries
  • JWT tokens supported (Auth0, JWKS, Firebase, etc)
  • Join database queries with remote REST APIs
  • Also works with existing Ruby-On-Rails apps
  • Rails authentication supported (Redis, Memcache, Cookie)
  • A simple config file
  • High performance Go codebase
  • Tiny docker image and low memory requirements
  • Fuzz tested for security
  • Database migrations tool
  • Database seeding tool
  • OpenCensus Support: Zipkin, Prometheus, X-Ray, Stackdriver
  • API Rate Limiting
  • Highly scalable and fast
  • Instant Hot-deploy and rollbacks
  • Add Custom resolvers

Documentation

Quick Start

Documentation

GraphJin GO Examples

Reach out

We're happy to help you leverage GraphJin reach out if you have questions

twitter/dosco

discord/graphjin (Chat)

License

[Apache Public License

编辑推荐精选

TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI辅助写作AI工具蛙蛙写作AI写作工具学术助手办公助手营销助手AI助手
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

下拉加载更多