Feature Request: make protocol buffer AST/parser SDK

Visto 791 veces
Saltar al primer mensaje no leído

Gerardo Mora

no leída,
16 feb 2021, 19:12:1516/2/21
a Protocol Buffers
Hello everyone, I would like to create an application that analyzes a .proto file and dynamically creates GraphQL queries, I don't want to parse the .proto files because it will outdated and probably buggy at some point, but I was reading the source code and the only available thing is create a plugin that ouputs a file after the processing which is not idea.

Is there an API/SDK available for it?  

Marc Gravell

no leída,
16 feb 2021, 19:24:1416/2/21
a Gerardo Mora,Protocol Buffers
You can use protoc to output the compiled schema (one of the command-line-options - something "file descriptor set"), and deserialize the resultant binary file as a FileDescriptorSet instance, deserializing via your choice of language via descriptor.proto - any use?

As an aside, I also have a separate implementation of a .proto parser, implemented in C#/.NET (so it can be used in 100% managed .NET code). Not sure if that is any use to you, but if so: let me know.

On Wed, 17 Feb 2021, 00:12 Gerardo Mora, <gmoras...@gmail.com> wrote:
Hello everyone, I would like to create an application that analyzes a .proto file and dynamically creates GraphQL queries, I don't want to parse the .proto files because it will outdated and probably buggy at some point, but I was reading the source code and the only available thing is create a plugin that ouputs a file after the processing which is not idea.

Is there an API/SDK available for it?  

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/f78681b8-47f2-44ac-955a-73b828f1b08dn%40googlegroups.com.

Derek Perez

no leída,
16 feb 2021, 19:28:5816/2/21
a Marc Gravell,Gerardo Mora,Protocol Buffers
It sounds like you may wanna build a protoc plugin like so:

The AST for protobuf is actually in protobuf itself! It's very easy to work with, and is the backbone of all the code generators.

Gerardo Mora

no leída,
16 feb 2021, 19:34:2816/2/21
a Derek Perez,Marc Gravell,Protocol Buffers
I'm gonna use golang for my project, and will be open source, so eventually I will show you the software if you guys are interested!
I would like that the parser will run in the same thread of the request, when a microservice registers itself.

I'm gonna read all approaches and see, thanks guys!

PS 
if there are more ideas all are welcomed.

--
May the source be with you!!!

Josh Humphries

no leída,
16 feb 2021, 21:27:5016/2/21
a Gerardo Mora,Derek Perez,Marc Gravell,Protocol Buffers
If you are using Go, you can use this protoparse package to parse proto source:
https://pkg.go.dev/github.com/jhump/protoreflect/desc/protoparse

It provides functions for parsing and linking into descriptors. But it also provides an option to parse into a richer AST. The descriptor format is not a particularly good AST because it is lossy. So if you wanted to write a formatter, for example, the descriptor loses a lot of token position and comment information, which may prevent you from perfectly reconstructing the original source text. The ast sub-package of protoparse is not lossy and includes position information, including whitespace and comments, for everything lexed token.
https://pkg.go.dev/github.com/jhump/protoreflect/desc/protoparse/ast

----
Josh Humphries
jh...@bluegosling.com


Gerardo Mora

no leída,
17 feb 2021, 11:18:5917/2/21
a Protocol Buffers
excellent option, I will use it!

Lim Afriyadi

no leída,
11 jul 2022, 23:39:5411/7/22
a Protocol Buffers
I've created a PoC to automate GraphQL API creation (code first approach) from protobuf using protobuf extension to define graphql query / mutation name. I'm using protogen package to iterate protobuf file definition. Maybe you would like to take a look https://github.com/ncrypthic/graphql-grpc-edge.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos