0.8.2 • Published 8 months ago

protoc-gen-nexus v0.8.2

Weekly downloads
169
License
MIT
Repository
github
Last release
8 months 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.8.2

8 months ago

0.8.1

1 year ago

0.7.0

1 year ago

0.6.6

1 year ago

0.6.5

2 years ago

0.6.4

2 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0-alpha.20

4 years ago

0.5.0-alpha.19

4 years ago

0.5.0-alpha.18

4 years ago

0.5.0-alpha.17

4 years ago

0.5.0-alpha.16

4 years ago

0.5.0-alpha.15

4 years ago

0.5.0-alpha.13

4 years ago

0.5.0-alpha.14

4 years ago

0.5.0-alpha.12

4 years ago

0.5.0-alpha.11

4 years ago

0.5.0-alpha.10

4 years ago

0.5.0-alpha.9

4 years ago

0.5.0-alpha.7

4 years ago

0.5.0-alpha.8

4 years ago

0.5.0-alpha.6

4 years ago

0.5.0-alpha.5

4 years ago

0.5.0-alpha.4

4 years ago

0.5.0-alpha.3

4 years ago

0.5.0-alpha.2

4 years ago

0.5.0-alpha.1

4 years ago

0.5.0-alpha.0

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.1

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago