Slash Lambda with Packages

Dgraph GraphQL Lambda Overview docs state:

Webpack is required to use the sample rank() function.

This seems to jive with dgraph/dgraph-lambda readme on Github

If you would like to add libraries, then use webpack --target=webworker to compile your script. We’ll fill out these instructions later.

I believe “these instructions” refer to compiling the lambda script with webpack. I believe Slash does this compiling for us already.

So… what packages can we import? Anything on npm? A list of approved packages? I would probably be able to answer this myself if I knew more about webpack and didn’t rely on React magic.

1 Like

For instance, currently I am wanting to make some queries to the Google Maps API, which requires Axios for the requests…

This is something I ran into today as well. I tried importing 'markdown-it' in my lambda script on Slash and it turns out to be an error

Yeah, you have to compile it if you want to import any packages. There is no current examples how to do this still though.

2 Likes

Ugh. Now I am gonna see if I can get away without installing any nodejs on my pristine-untouched-by-js computer.

1 Like

@amaster507 You did the auth thing with a @custom on netlify… is netlify free or do I have to pay?

It has a free tier. Can’t remember how many calls per month you get but it is a fair amount. AWS also has a free tier for lambdas I believe.

1 Like

I noticed @amaster507 never really got an answer to his question. I have the same question. Is there more information somewhere that I’ve just missed?

Also, the dgraph docs have, instead of “[filling out] these instructions later”, simply removed that line where they say they’ll fill out the instructions later. :smile:

You have to compile your scripts into an output that will also include the packages you want to include and then copy and paste all of that output into the lambda script. It is not pretty or friendly. I just found an alternative lambda provider when my scripts need packages to be compiled but that loses a little bit of the power and purpose of Dgraph having the lambda close to the db.

Another reason why the “almighty” lambda is not always the best solution. It would be better if it was to work more closely like Auth0 uses custom scripts.

1 Like

Most libraries with work with lambda if they are

  • written in pure JS (no c++ extensions )
  • do not try to access file system or environment.

I think the “fill this out later” went onto the lambda docs site. But basically: use Webpack to make a single file.