# Why Javascript for dgraph-lambda?

**URL:** <https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289>\
**Category:** GraphQL\
**Tags:** kind:question, kind:enhancement\
**Created:** [November 4, 2020, 5:30pm UTC](https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289 "2020-11-04T17:30:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maaft](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maaft](https://discuss.dgraph.io/u/maaft)\
**Post date:** [November 4, 2020, 5:30pm UTC](https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289/1 "2020-11-04T17:30:41Z")

</div>

I was wondering why you went for javascript for dgraph-lambda? Couldn’t you just allow implementation of custom resolvers in golang?

Javascript just makes cross-platform-shipping of lambda functionality a real pain.

---

<div class="post-metadata">

**Author:** ![miko](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/miko/32/2493_2.png) [@miko](https://discuss.dgraph.io/u/miko)\
**Post date:** [November 22, 2020, 11:17pm UTC](https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289/2 "2020-11-22T23:17:11Z")

</div>

I think there are two main reasons:

1. most of the users of GraphQL are frontend developers, and they do know javascript
2. there are some advantages of using interpreted languages: you can store your logic as a data (in dgraph itself) and easily update it without recompilation/deployment.

Still, I would prefer lua as a script language.

You can check out my take on the lambda solution: [GitHub - miko/dgraph-luambda: Dgraph Luambda is a serverless platform for running Lua on Slash GraphQL (or Dgraph). Inspired by original Dgraph Lambda](https://github.com/miko/dgraph-luambda)  
There are examples of custom resolvers both in golang and lua.

Note: it is not production ready, just proof of concept.

---

<div class="post-metadata">

**Author:** ![maaft](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maaft](https://discuss.dgraph.io/u/maaft)\
**Post date:** [January 20, 2021, 11:15am UTC](https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289/3 "2021-01-20T11:15:55Z")

</div>

Can someone of the team maybe step in and explain the reasoning behind this?

Dgraph is shipped cross-plattform but dgraph-lambda is currently not. Can we expect to have a cross-plattform lambda server at some time?

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [January 20, 2021, 11:42am UTC](https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289/4 "2021-01-20T11:42:50Z")

</div>

Hi @maaft, thanks for the question.

Any http server can be used as a lambda server, as long as it honors a very simple http endpoint interface.

We chose Javascript for the initial implementation, and the version that Is used for slash graphql for a few reasons

- maximize developer reach, especially to the front end crowd
- ability to lock down what the language can do (I don’t need someone to attempt to run a bot net from a lambda). Node provides this via vm isolates and contexts. As an example, fetch is the only way to do any IO from dgraph lambda.

The dgraph-lambda project just takes a function, wraps it in all this security context, and serves it as an http endpoint. Its a fairly thin wrapper. Dgraph-lambda can be launched via docker, so that may provide the cross platform nature you are looking for.

Tejas

---

<div class="post-metadata">

**Author:** ![maaft](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maaft](https://discuss.dgraph.io/u/maaft)\
**Post date:** [January 20, 2021, 11:59am UTC](https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289/5 "2021-01-20T11:59:31Z")

</div>

Okay, thank you for the explanation.

I think I’ll have to read a bit more into the lambda code to understand it and write my own server then.

---

<div class="post-metadata">

**Author:** ![maaft](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maaft](https://discuss.dgraph.io/u/maaft)\
**Post date:** [May 7, 2021, 11:26am UTC](https://discuss.dgraph.io/t/why-javascript-for-dgraph-lambda/11289/6 "2021-05-07T11:26:58Z")

</div>

If anyone is interested: I have a working example lambda server in pure golang. The code is not very clean yet so I won’t publish it for now. Also some features are still missing. If you still want to use it - shoot me a message.
