All Projects → marwan-at-work → protoc-gen-twirpql

marwan-at-work / protoc-gen-twirpql

Licence: Apache-2.0 license
Generate A GraphQL Layer from A Twirp Server: https://twirpql.dev

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to protoc-gen-twirpql

Altair
✨⚡️ A beautiful feature-rich GraphQL Client for all platforms.
Stars: ✭ 3,827 (+7710.2%)
Mutual labels:  graphql-client, graphql-server, graphiql
DotNetGraphQL
A sample demonstrating how to create a GraphQL Backend in .NET and consume it from a .NET mobile app created using Xamarin
Stars: ✭ 78 (+59.18%)
Mutual labels:  graphql-client, graphql-server, graphiql
Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+1048.98%)
Mutual labels:  graphql-client, graphql-server
Caliban
Functional GraphQL library for Scala
Stars: ✭ 581 (+1085.71%)
Mutual labels:  graphql-client, graphql-server
Locksmith
Want to use GraphQL with Clojure/script but don't want keBab or snake_keys everywhere? Use locksmith to change all the keys!
Stars: ✭ 59 (+20.41%)
Mutual labels:  graphql-client, graphql-server
character-overlay
Web App for adding an OBS overlay with character information such as name, picture, and health for your favorite role-playing game.
Stars: ✭ 17 (-65.31%)
Mutual labels:  graphql-client, graphql-server
Morpheus Graphql
Haskell GraphQL Api, Client and Tools
Stars: ✭ 285 (+481.63%)
Mutual labels:  graphql-client, graphql-server
Graphql Kotlin
Libraries for running GraphQL in Kotlin
Stars: ✭ 1,030 (+2002.04%)
Mutual labels:  graphql-client, graphql-server
nim-graphql
Nim implementation of GraphQL with sugar and steroids
Stars: ✭ 47 (-4.08%)
Mutual labels:  graphql-client, graphql-server
Gqlify
[NOT MAINTAINED]An API integration framework using GraphQL
Stars: ✭ 182 (+271.43%)
Mutual labels:  graphql-client, graphql-server
Graphql Stack
A visual explanation of how the various tools in the GraphQL ecosystem fit together.
Stars: ✭ 117 (+138.78%)
Mutual labels:  graphql-client, graphql-server
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (+6040.82%)
Mutual labels:  graphql-client, graphql-server
Messenger
Open source, native iOS Messenger, with realtime chat conversations (full offline support).
Stars: ✭ 4,264 (+8602.04%)
Mutual labels:  graphql-client, graphql-server
relay-compiler-plus
Custom relay compiler which supports persisted queries
Stars: ✭ 68 (+38.78%)
Mutual labels:  graphql-client, graphql-server
fullstack-graphql-angular
Simple Fullstack GraphQL Application with Angular CLI + Redux. API built with Typescript + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with Angular CLI + Redux + Async Middleware to access the API.
Stars: ✭ 67 (+36.73%)
Mutual labels:  graphql-client, graphql-server
Fullstack Graphql
🌈 Simple Fullstack GraphQL Application. API built with Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux to access the API. Written in ES6 using Babel + Webpack.
Stars: ✭ 955 (+1848.98%)
Mutual labels:  graphql-client, graphql-server
finch-sangria
A simple wrapper for using Sangria from within Finch.
Stars: ✭ 33 (-32.65%)
Mutual labels:  graphql-server, graphiql
Qlens
QLens is an electron app which dynamically generates GraphQL Schemas and Mongo Schema visualization. QLens significantly cuts development time by automating the formation of their GraphQL schemas based on information fetched from their non-relational database.
Stars: ✭ 110 (+124.49%)
Mutual labels:  graphql-client, graphql-server
36 Graphql Concepts
📜 36 concepts every GraphQL developer should know.
Stars: ✭ 209 (+326.53%)
Mutual labels:  graphql-client, graphql-server
showcase
A Full Stack Journey with Micro Services and Micro Front Ends. Using dapr, kubernetes, react module federation and web assembly,
Stars: ✭ 45 (-8.16%)
Mutual labels:  graphql-client, graphql-server

A Protoc plugin that generates a GraphQL layer on top of Twirp servers.

Status

There have been a few breaking changes in the upstream dependencies (protobufs and gqlgen) which makes this plugin a bit outdated if not flat out broken. So the go.mod file to pin the versions that would work with this library or feel free to open a PR upgrading to the latest of the two versions. See #9

Features

  • Generates a full GraphQL server implementation based on gqlgen

  • Marshals/Unmarshals ProtoBuf enums (ints) to GraphQL enums (strings).

  • Generates GraphQL Scalars for Protobuf map types that can be used as encoded json strings.

  • Exposes a GraphQL handler as well as a Graph(i)QL interface to make Twirp servers interactive.

  • Unit tests and end to end tests.

  • Twirp Server Hooks -> GraphQL Middleware

Why

RPC Frameworks such as Twirp have two big benefits:

  1. Automatic client generation
  2. Documentation-first APIs ensure your contract is not out of date.

This makes it really easy for multiple teams to start using your program right away. But before they use it, they need to learn how it works. This is where GraphQL does a better job.

Twirp and many other frameworks do not provide a friendly UI to discover and interact with their services. GraphQL comes with a very friendly UI that makes discovering an API quick, easy and fun. You get expressiveness and auto-completion out of the box.

By combining both technologies, my hope is that you get the best of both worlds.

Install

GO111MODULE=on go install marwan.io/protoc-gen-twirpql

Usage

For a full tutorial, click here.

protoc --go_out=. --twirp_out=. service.proto
protoc --twirpql_out=. service.proto

This will generate a subpackage that you can import and use as such:

package main

import (
    "net/http"

    "./twirpql"
    "./mytwirpserver"
)

func main() {
    s := mytwirpserver.New()
    http.Handle("/query", twirpql.Handler(s, nil))
    http.Handle("/play", twirpql.Playground("my service", "/query"))
}

Server Hooks

TwirpQL supports mapping the Error callback of twirp.ServerHooks to a GraphQL middleware.

All you have to do is the following:

    hooks := &twirpql.Handler{Error: myErrorHook}
    http.Handle("/query", twirpql.Handler(s, hooks))

And TwirpQL will call your hook if the underlying service implementation returned an error.

Workflow

TwirpQL expects the service.proto to have already been used to generate a .pb.go, and .twirp.go files in the same directory as the .proto file.

The plugin will generate a twirpql sub-package that contains the GraphQL layer with all types mapped to the original .pb.go file generated by your .proto file.

Multiple Services

Currently you can only specify one target file such as service.proto. In other words, the following is not allowed:

protoc --twirpql_out=. service.proto otherservice.proto

That said, service.proto can import multiple protofiles so breaking out your proto files should not be problem.

However, each TwirpQL generation is meant for one service declaration in a protocol buffer file. If a Protobuf file has one service declaration, that will be the one chosen. If the Protobuf file has multiple service declarations, then you must explicitly specify which service you'd like to generate a GraphQL layer for as such:

protoc --twirpql_out=service=SomeService:. service.proto

If you want to generate a GraphQL layer over multiple services, see here

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].