Angular build breaks for browser when trying to use the dgraph http client due to reliance on jsonwebtokens that in turn require Buffer in browser

I Want to Do

I would like to use the dgraph-js-http within my angular application to communicate with a self-hosted Dgraph cluster. Also I would like to use this client with dql and not just graphql as I need ability to do groupby and facets.

What I Did

I have a standalone Dgraph instance running locally and also a angular application setup. Unfortunately the dgraph-js-http client has a dependency on jsonwebtokens which in turn depends upon a few libraries like crypto, stream, buffer etc that are not available in a browser context. Angular from version 6 has stopped allowing the use of such libraries within its context, please see below:

I modified my tsconfig and polyfills for global/buffer but kept on getting the issue with other libraries that are node specific being depended upon by dgraph-js-http (jsonwebtokens). The Dgraph documentation clearly states this client supports browser environments but it relies heavily on libraries that are specific to node environments.

Is there any workaround for this or any fix planned?

Dgraph Metadata

dgraph version

version: 20.11.0

Nope, and I think it wouldn’t be fixed cuz it isn’t a dgraph-js-http issue. It is a third party decision. The jsonwebtoken is necessary for Slash. We would need to drop Slash support to make it work for Angula. As far I can see.

BTW, none of our clients are meant to be running on client level (browser for example). You should create an API. That’s why the client works better in the NodeJS context.

You can use custom DQL or Lambda with DQL. And that procedure you need to do, will be available in GraphQL.

Hi Michel,

Thanks for the response.

Yes personally I do not entirely agree with the reasoning of the angular team for dropping support for browser ports of node specific libraries though I understand their point with regards to client frameworks like Angular only supporting browser specific libraries. I imagine this will create a lot of issues for the Angular community as it can be turned into a he said/she said situation between Angular and other libraries dependent on node specific modules.

In turn I did give up and just moved onto setting up a express API and that seems to be working fine. I was simply being too hasty in wanting to try things out locally. So for anyone else that comes across this issue while trying to get Angular to work with the client, best to just setup a small API and use the various client libraries available from Dgraph in your backend.

1 Like

Hi!

I stumbled upon the same problem. But this can be conveniently be monkey patched.

Making web3/bitcore-lib work with Angular 6-11 and >=11 (github.com)

Just tried it with a fresh Angular 11 app and could retrieve the Data from Dgraph backend no problem. Before the monkey patch the error you named gave me trouble as well.

1 Like