Need help: How do I go about figuring out what causes my GraphQL query to fail when using standalone:master?

I want to test out a new feature that has been merged into master: WIP: Auth rules custom DQL query

My custom query works fine using the Dgraph standalone docker image:

docker run -it -v ~/dev/dgraph:/dgraph -p 8000:8000 -p 8080:8080 -p 9080:9080 dgraph/standalone:21.03

However, when I use the standalone:master image I get the following error:

docker run -it -v ~/dev/dgraph:/dgraph -p 8000:8000 -p 8080:8080 -p 9080:9080 dgraph/standalone:master

Can’t figure out how to fix this, and no idea whether it’s a bug in master or that my schema is incompatible with the version of Dgraph that currently exists in master?

Is there a more sensible way to test out a feature, perhaps I should be forking Dgraph then creating a docker image just for this PR branch??

Well, using dgraph/standalone:latest, (no errors) works fine instead of dgraph/standalone:master, so I guess that’s the solution.

EDIT: Oh, but that’s Dgraph v23.0.1 which doesn’t contain the commits I want to test. :thinking:

Can you try with the default value?

query Something($keyword: keyword = "something") {
 ....
}

But that feels like a bug…
Could you try to build it locally and try to run it locally? Also from scratch, not reusing the previous files from other version.

I’m not sure how to add a default value a @custom graphql query with embedded DQL?

I actually had this issue before come to think of it—Use GraphQL Vars In regex - #5 by noisykeyboard

I’ve tried various syntaxes, can’t get it to work:

type Metadata @auth(
  query: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
  add: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
  update: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
  delete: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
){
  total_count: Int
}
  queryTranscriptsIndexMetadata(keyword: keyword = "//i"): Metadata @custom(dql: """
    query q($keyword: string) {
      var(func: type(Transcript)) @filter(regexp(Transcript.name, $keyword)) {
        a as count(uid)
      }

      queryTranscriptsIndexMetadata() @normalize {
        total_count : sum(val(a))
      }
    }
   """)
  queryTranscriptsIndexMetadata(keyword: String!): Metadata @custom(dql: """
    query q($keyword: string = "//i") {
      var(func: type(Transcript)) @filter(regexp(Transcript.name, $keyword)) {
        a as count(uid)
      }

      queryTranscriptsIndexMetadata() @normalize {
        total_count : sum(val(a))
      }
    }
   """)
  queryTranscriptsIndexMetadata(keyword: String!): Metadata @custom(dql: """
    query q($keyword: keyword = "//i") {
      var(func: type(Transcript)) @filter(regexp(Transcript.name, $keyword)) {
        a as count(uid)
      }

      queryTranscriptsIndexMetadata() @normalize {
        total_count : sum(val(a))
      }
    }
   """)
  queryTranscriptsIndexMetadata(keyword: String!): Metadata @custom(dql: """
    query q($keyword = "//i") {
      var(func: type(Transcript)) @filter(regexp(Transcript.name, $keyword)) {
        a as count(uid)
      }

      queryTranscriptsIndexMetadata() @normalize {
        total_count : sum(val(a))
      }
    }
   """)
  queryTranscriptsIndexMetadata(keyword: String! = "//i"): Metadata @custom(dql: """
    query q($keyword: string = "//i") {
      var(func: type(Transcript)) @filter(regexp(Transcript.name, $keyword)) {
        a as count(uid)
      }

      queryTranscriptsIndexMetadata() @normalize {
        total_count : sum(val(a))
      }
    }
   """)

Would also appreciate some instructions on how to build a Docker image from a specific commit—I’ll go back through the commits until I figure out which one causes the issue.
EDIT: Looks like I can just use GitHub - MichelDiz/dgraph_master: Build Dgraph from master branch (nightly? Dgraph binary - Alpine), and clone/checkout a specific commit before building.

EDIT: This one works in v21.03 (But not on master):

  queryTranscriptsIndexMetadata(keyword: String!): Metadata @custom(dql: """
    query q($keyword: string = "//i") {
      var(func: type(Transcript)) @filter(regexp(Transcript.name, $keyword)) {
        a as count(uid)
      }

      queryTranscriptsIndexMetadata() @normalize {
        total_count : sum(val(a))
      }
    }
   """)
1 Like

Hi Michel, I’ve tried building Dgraph standalone from the last commit in the minhaj/custom-auth branch, and also from the squash commit in master but still get the issue, so I’m concluding that this is a bug caused by an earlier commit in master.

Here’s a simple schema you can reproduce it with, would appreciate it if you could take a look at it:

type Thing {
  id: ID!
  name: String! @search(by: [regexp])
}

type Query {
  queryThingsCount(keyword: String!): Count @custom(dql: """
    query q($keyword: string = "//i") {
      var(func: type(Thing)) @filter(regexp(Thing.name, $keyword)) {
        a as count(uid)
      }

      queryThingsCount() @normalize {
        total_count : sum(val(a))
      }
    }
   """)
}

type Count {
  total_count: Int
}

The query:

query ExampleQuery($keyword: String!) {
  queryThingsCount(keyword: $keyword) {
    total_count
  }
}
{
  "keyword": "/a search term/i"
}

The dockerfile I used to get standalone working:

FROM golang:alpine AS builder

RUN apk update && apk add --no-cache git make build-base curl

RUN mkdir -p $GOPATH/src/github.com/dgraph-io/

WORKDIR $GOPATH/src/github.com/dgraph-io/

#! If you wanna build always the latest commit, uncomment the next line. But this will take time to build.
#! Also remove the line 13 with the COPY command. And you you don't need to clone Dgraph repo again.
#RUN git clone -v --progress https://github.com/dgraph-io/dgraph.git

COPY . .

RUN cd dgraph && make install

FROM golang:alpine

COPY --from=builder /go/bin/dgraph /go/bin/dgraph

RUN mkdir /dgraph
WORKDIR /dgraph

EXPOSE 8080
EXPOSE 9080

ADD run.sh /run.sh
RUN chmod +x /run.sh
CMD ["/run.sh"]

run.sh: (Had to change #!/bin/bash to #!/bin/sh for this to work on my Mac)

#!/bin/sh

# fail if any error occurs
set -e

echo -e "\033[0;33m
Warning: This standalone version is meant for quickstart purposes only.
         It is NOT RECOMMENDED for production environments.\033[0;0m"

# For Dgraph versions v20.11 and older
export DGRAPH_ALPHA_WHITELIST=0.0.0.0/0
# For Dgraph versions v21.03 and newer
export DGRAPH_ALPHA_SECURITY='whitelist=0.0.0.0/0'

# TODO properly handle SIGTERM for all three processes.
dgraph zero & dgraph alpha

EDIT: btw, your dgraph_master Dockerfile doesn’t work as a standalone build without the run.sh file to boot both zero and alpha, do you want me to submit a PR, or is it not meant for building a standalone? Otherwise a create a separate repo with some instructions.

I’ll accept this and put in the backlog.

The intention is just to have a master build. Not a standalone.
The standalone build can use that master build tho. Locally.

1 Like