GRPC and Node, getting errors

I’m having a hard time getting the javascript GRPC client working in Node, specifically NestJS. I’ve been using this for reference: GitHub - val-samonte/nestjs-dgraph: dgraph-js module for Nest

I’m not using this package, I copied the code, updated it, and made it into its own module in my NestJS server. But the principles are basically the same. I’m using the latest dgraph-js package, for example.

It looks like I’m connecting to the GRPC endpoint just fine (the one you access through the settings page on Dgraph Cloud, ending in 443). I’m kind of a noob with this stuff so I’m just using “createInsecure()” for the credentials, with no options. Everything about the client setup looks like its working, but when I try to fire off a query I get this:

[Nest] 12580  - 07/25/2021, 6:18:15 PM   ERROR [ExceptionsHandler] 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: Protocol error
Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: Protocol error

There must be something obvious I’m missing here. The reason I’m doing this is because I’m running an angular app that’s being rendered server-side through a NestJS server, which I also plan to use to generate JWTs and their claims, and get that all working with Dgraph Cloud. Having GRPC would just make the performance that much better.

Report a Dgraph Client Bug

What Dgraph client (and version) are you using?

(put “x” in the box to select)

  • Dgo
  • PyDgraph
  • Dgraph4J
  • Dgraph-js
  • Dgraph-js-http
  • Dgraph.NET

Version:

What version of Dgraph are you using?

v21.03.0-56-gc900f96b3

Have you tried reproducing the issue with the latest release?

What is the hardware spec (RAM, OS)?

MacOS, 32GB

Is this perhaps related to this issue? Dgraph internal client RST_STREAM errors and timeouts - #2 by dmai

@jmarlow4 This looks related to the other topic you linked. Can you share the endpoint of your backend (feel free to DM me). We have been rolling out the fix for this and the rollout should be complete by tomorrow.

@jmarlow4 Thanks for sharing your endpoint over DM. How often are you seeing this error?

You shouldn’t use createInsecure(). That wouldn’t work because connection to your Dgraph Cloud backend must go over TLS (encrypted). We don’t want anyone spoofing your traffic.

In dgraph-js there’s an endpoint to make it easy to connect to your Dgraph Cloud backend: Advanced Queries with DQL - Dgraphcloud. You can pass in your backend endpoint and API like the doc example:

const dgraph = require("dgraph-js");

const clientStub = dgraph.clientStubFromCloudEndpoint(
  "https://frozen-mango.eu-central-1.aws.cloud.dgraph.io/graphql",
  "<api-key>"
);
const dgraphClient = new dgraph.DgraphClient(clientStub);

That example is for HTTP, isn’t it? I’m looking for GRPC, and I was wondering if createInsecure() would keep it from working. If that’s the case, would using that setting result in the error I’m getting when I try to run a query over GRPC?

I was under the impression that TLS was only necessary if I hosted the instance myself. Can I create a client stub from cloud endpoint over GRPC without TLS? Because some of the examples in the documentation use createInsecure() but its with an instance thats locally hosted.

So I just tried it and it worked! And it worked with DQL out of the box, which profoundly confuses me. I thought the /graphql path only accepted GraphQL queries… is this not the case? Does it also take DQL natively?

The API endpoint takes in the endpoint with /graphql (the same endpoint shown in your Dgraph Cloud dashboard) and derives the gRPC endpoint to connect to. It doesn’t actually connect to the /graphql endpoint.

dgraph-js connects over gRPC and supports DQL only.

TLS is required.

That’s correct. The documentation around createInsecure is for Dgraph instances running locally, not in Dgraph Cloud.

Thank you for all your help! You guys are doing incredible, revolutionary work over there!