prisma-labs / graphqlgen

⚙️ Generate type-safe resolvers based upon your GraphQL Schema
MIT License
818 stars 54 forks source link

Idea: gRPC plugin #255

Open schickling opened 6 years ago

schickling commented 6 years ago

It's a very common use-case to use GraphQL as a gateway (as opposing to a GraphQL monolith/service) in front of other services (e.g. gRPC, Thrift, ...). I'd like to explore the possible workflows of using graphqlgen to auto-generate/auto-scaffold resolvers mapping to gRPC services.

My current idea would be to create a scaffolding plugin (see #84) which instead of scaffolding a resolver that throws an error, actually scaffolds a runnable resolver that calls out to the corresponding gRPC service.

The needed configuration/mapping could either be provided via some namespace in graphqlgen.yml or partially in the application schema via schema directives. Here's an idea how the config could look like in the graphqlgen.yml

# ...

resolver-scaffolding:
  output: ./src/generated/tmp-resolvers/
  layout: file-per-type
  plugins:
    grpc:
      input: ./my-service.proto
      resolvers:
        Query:
          feed: GetPosts
        Mutation:
          createDraft: NewDraft

Related: https://github.com/99designs/gqlgen/issues/228

Open Questions

vektah commented 6 years ago

We are considering something similar for gqlgen.

A few things I would love to see:

Some more questions:

What should be the plugin/config "input"? Do we assume there's already a generated TS gRPC client or is it the responsibility to also generate one (including the resulting model type definitions) based on a .proto file?

At 99designs all of our clients are generated when the downstream apps merge, and are pushed to a shared repo, so this wouldn't be super useful and might be kinda tricky to do well?