Running dgraph/standalone along with dgraph/dgraph-lambda

Report a Dgraph Bug

What version of Dgraph are you using?

I’m trying to run dgraph along with lambda server, using the compose file suggested here
https://dgraph.io/docs/graphql/lambda/server/

with the following image ids

dgraph/standalone 6c33c6b3864c, dgraph/dgraph-lambda 2e3fbba153b9
$ dgraph version
 
Dgraph version   : v21.03.0
Dgraph codename  : rocket
Dgraph SHA-256   : b4e4c77011e2938e9da197395dbce91d0c6ebb83d383b190f5b70201836a773f
Commit SHA-1     : a77bbe8ae
Commit timestamp : 2021-04-07 21:36:38 +0530
Branch           : HEAD
Go version       : go1.16.2

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

Docker on MacOS

Steps to reproduce the issue (command/config used to run Dgraph).

I’m trying to run dgraph along with lambda server. When I’m trying to update the schema that contains @lambda directive, the command would return an error that --graphql “lambda-url=…;” flag wasn’t specified during alpha startup. I assume the environment variable DGRAPH_ALPHA_GRAPHQL_LAMBDA_URL would take care of the flag
Using the following docker-compose.yml provided here https://dgraph.io/docs/graphql/lambda/server/
docker-compose.yml

version: "3.8"
services:
  dgraph:
    image: dgraph/standalone:latest
    environment: 
      DGRAPH_ALPHA_GRAPHQL_LAMBDA_URL: "http://dgraph_lambda:8686/graphql-worker"
    ports:
      - "8080:8080"
      - "9080:9080"
      - "8000:8000"
    volumes:
      - dgraph:/dgraph

  dgraph_lambda:
    image: dgraph/dgraph-lambda:latest

    ports:
      - "8686:8686"
    environment:
      DGRAPH_URL: http://dgraph:8080
    volumes:
      - ./gql/script.js:/app/script/script.js:ro

volumes:
  dgraph: {}

gql/schema.gql

type Test {
  number: Float
  luckyNumber: Float @lambda
}

gql/script.js

self.addGraphQLResolvers({
  "Test.luckyNumber": () => Math.random()
})

running the command

docker-compose up

then when the server is started run

curl -X POST localhost:8080/admin/schema --data-binary '@gql/schema.gql'

Expected behaviour and actual result.

Expected behaviour:
output

{"data":{"code":"Success","message":"Done"}}%    

actual result

{"errors":[{"message":"resolving updateGQLSchema failed because input:3: Type Test; Field luckyNumber: has the @lambda directive, but the --graphql \"lambda-url=...;\" flag wasn't specified during alpha startup.\n (Locations: [{Line: 3, Column: 4}])","extensions":{"code":"Error"}}]}

That’s the issue. You have to build your own standalone image to make it work.

How should I do that? So you are saying that the url is set during the url is set during build time and not container runtime?
from https://dgraph.io/docs/graphql/lambda/server/#docker-settings
I thought DGRAPH_ALPHA_GRAPHQL_LAMBDA_URL was supposed to set a runtime flag equivalent to --graphql lambda-url

Yes, see these files https://github.com/dgraph-io/dgraph/blob/master/contrib/standalone/

The standalone runs automatically two nodes. One Zero isntance and an Alpha. So, you won’t add any new param/config to that. You have to copy that files at dgraph/contrib/standalone/run.sh and add the flags manually.

Pay attention that this image wasn’t made for production. If you are investing in some fancy features, you should run your own cluster instead of the standalone.

Cheers.

PS;

Good theory, but the machine won’t lie. If it throws the error, is that it isn’t working as expected. Maybe it is an issue with the way Docker build its images. Both nodes are executed in a single shot before the actual execution of the image. In a normal image the binary isn’t executed right away. You have to pass the command in order to run it. But in the standalone, it runs all for you.

Thank you so much, I was able to get it working.

Pay attention that this image wasn’t made for production. If you are investing in some fancy features, you should run your own cluster instead of the standalone.

Thanks for the heads-up, this is just for local development. I’m using Dgraph Cloud for production :smiley:

1 Like