0.7.0 • Published 14 days ago

protoc-gen-nexus v0.7.0

Weekly downloads
169
License
MIT
Repository
github
Last release
14 days ago

ProtoNexus

Protobuf-First GraphQL Schemas with GraphQL Nexus

Packages

packagedescriptionversion
protoc-gen-nexusprotoc plugin for generating Nexus type definitionsnpm version
@proto-nexus/google-protobufRuntime librarynpm version
@proto-nexus/protobufjsRuntime librarynpm version
@proto-nexus/proto-fields-pluginNexus plugin for building subset types from proto-nexus's artifactsnpm version

Installation

yarn add nexus graphql  # required as a peer dependency
yarn add --dev protoc-gen-nexus

# if you generate code with `protoc --js_out`
yarn add @proto-nexus/google-protobuf \
  google-protobuf @types/google-protobuf  # required as a peer dependency

# if you generate code with protobufjs
yarn add @proto-nexus/protobufjs \
  protobufjs  # required as a peer dependency

Usage

Generate GraphQL Types from Protobuf IDL

To generate Nexus type definitions from .proto files, you need to invoke following command:

protoc \
  -I ./node_modules/protoc-gen-nexus/include \
  -I <YOUR_PROTO_PATH> \
  --plugin=protoc-gen-nexus=`yarn bin protoc-gen-nexus` \
  --nexus_out=<DIST_DIR> \
  --nexus_opt="import_prefix=<YOUR_PROTO_PATH_OR_PACKAGE>" \
  path/to/file.proto

with protobufjs

proto-nexus supports protobufjs with static code generated by protobufjs CLI.

# `target`, `wrap` and `force-message` options are required.
# An output file name must be `index.js`.
pbjs \
  --target static-module \
  --wrap commonjs \
  --force-message \
  --path <YOUR_PROTO_PATH> \
  --out "<DIST_DIR>/index.js" \
  path/to/package/*.proto

# An output file name must be `index.d.ts`
pbts --out "<DIST_DIR>/index.d.ts" "<DIST_DIR>/index.js"

And protoc-gen-nexus requires use_protobufjs option.

  --nexus_opt="import_prefix=<YOUR_PROTO_PATH_OR_PACKAGE>,use_protobufjs" \

Make schema

See also Best Practices - GraphQL Nexus.

// src/schema/types/index.ts

// Export generated types
export * from "./path/to/generated_types/...";
export * from "./path/to/generated_types/...";
// ...

When makeSchema, abstractTypeStrategies must have isTypeOf: true.

import { makeSchema } from "nexus";
import "@proto-nexus/google-protobuf";  //  should import runtime library
import * as allTypes from "./schema/types";

export const schema = makeSchema({
  types: alltypes,
  output: { /* ... */ },
  features: {
    abstractTypeStrategies: {
      isTypeOf: true,
    },
  },
})

Author

0.7.0

14 days ago

0.6.6

3 months ago

0.6.5

7 months ago

0.6.4

7 months ago

0.5.4

1 year ago

0.5.3

2 years ago

0.5.6

1 year ago

0.5.5

1 year ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.0-alpha.20

3 years ago

0.5.0-alpha.19

3 years ago

0.5.0-alpha.18

3 years ago

0.5.0-alpha.17

3 years ago

0.5.0-alpha.16

3 years ago

0.5.0-alpha.15

3 years ago

0.5.0-alpha.13

3 years ago

0.5.0-alpha.14

3 years ago

0.5.0-alpha.12

3 years ago

0.5.0-alpha.11

3 years ago

0.5.0-alpha.10

3 years ago

0.5.0-alpha.9

3 years ago

0.5.0-alpha.7

3 years ago

0.5.0-alpha.8

3 years ago

0.5.0-alpha.6

3 years ago

0.5.0-alpha.5

3 years ago

0.5.0-alpha.4

3 years ago

0.5.0-alpha.3

3 years ago

0.5.0-alpha.2

3 years ago

0.5.0-alpha.1

3 years ago

0.5.0-alpha.0

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.1

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

4 years ago