Minimal Dgraph example for newbies


(Todsaporn Banjerdkit) #1

Refer to

{
  debug(allof("type.object.name.en", "steven spielberg")) {
    type.object.name.en
    film.director.film {
      type.object.name.en
      film.film.initial_release_date
      film.film.country
      film.film.starring {
        film.performance.actor {
          type.object.name.en
        }
        film.performance.character {
          type.object.name.en
        }
      }
      film.film.genre {
        type.object.name.en
      }
    }
  }
}

It’s great for huge and complex example but it’s not reflex simplicity of GraphQL from my noob perspective. e.g. I can do this in GraphQL

{
  hello
}

and resolve world back like…

{
  hello : "world"
}

The question is how can I do hello world like this via Dgraph?

Thanks and sorry if this seem to be a stupid question.


(Manish R Jain) #2

Hey @katopz,

Good point about the complexity of examples. What do you think about these here:
https://wiki.dgraph.io/Get_Started


(Todsaporn Banjerdkit) #3

Hi @mrjn , It’s look pretty much same just shorter.

{
  debug(allof("type.object.name.en", "steven spielberg")) {
    type.object.name.en
    film.director.film (orderdesc: film.film.initial_release_date) {
      type.object.name.en
      film.film.initial_release_date
    }
  }
}

I can see plenty type.object.name.en that I didn’t know do I need it or not (Maybe it’s for localize?) and some repeat itself of film.film for some reason everywhere, the thing is I didn’t realize what it is so I try to figure out from goldendata.schema

scalar (
  type.object.name.en: string @index
  film.film.initial_release_date: date @index
)

Still no go,schema I know from GraphQL is longer maybe it’s a good news that’s shorter.
How about goldendata.rdf.gz, oh it’s goldendata.rdf and I didn’t know how to deal with it.

As you can see, I’m pretty much stuck to create simple hello world. Here’s what in my head now.

{
  debug(allof("type.object.name.en", "foo")) {
    type.object.name.en
    hello
  }
}

and hello.schema

scalar (
  type.object.name.en: string @index
  hello: string @index
)

But what about rdf? What’s look like? Or maybe I can just mutate some data in? e.g.

$ curl localhost:8080/mutation -XPOST -d `mutation { set { <hello>  "world" } }`

PS : Above code is just my imagination. I think I need more luck to make it work so I decide to asking here instead.

Thanks


(Ashwin) #4

Hi @katopz, Let us know if this helps you: Schema for get employees for some boss and get boss for some employees


(Todsaporn Banjerdkit) #5

Hi @ashwin95r That’s pretty close! Now I know how to proper mutation and now I know I didn’t need type.object.name.en.

Next question is what is p and w there? Do I need it?

# Running dgraph image with the directories mounted.
$ docker run -it -p 8080:8080 -v $(pwd)/p:/dgraph/p -v $(pwd)/w:/dgraph/w dgraph/dgraph dgraph -schema goldendata.schema

And I don’t think goldendata.schema is exist there I’ve to cp in container or use mount volume.

Thanks


(Pawan Rawal) #6

Hey @katopz

We have goldendata.schema bundled into the the Docker image, so you don’t need to mount volume for it. If you want to use some other schema then you would have to mount it.

The p and w directories are used by Dgraph for persisting your data. If you want to persist your data then you should mount them.


(Todsaporn Banjerdkit) #7

@pawan Thanks, I thought it was just example at first, And do I need goldendata.schema to run Dgraph ?
If not, why it embed in Docker?


(Pawan Rawal) #8

Hey @katopz, no you don’t need it absolutely to run Dgraph. But you need it if you want to load the golden data set on the Get started page and perform the queries there. It doesn’t need to be embedded in Docker.

You could download it and mount it like the p and w volume if you need it.


(Todsaporn Banjerdkit) #9

IMHO

  1. Document should provide what p and w volume for.
  2. goldendata.schema should be remove. (see #3)
  3. Document should provide how to add goldendata.schema as volume data instead of embed it in container.
  4. Document should provide other way to add simple data (mutation) not just rdf
  5. Document should also provide expected output after example command because something like ErrorOK is made me unsure it’s error or ok or both.

Do tell me if you need my noob/bad gramma PR before I do blog post about this.
Can’t wait to use Dgraph on my side project. Seem fun enough.

Thanks! Appreciate all support! :slight_smile:


(Manish R Jain) #10

Hi @katopz,

Thanks for the feedback. We’ll make these changes. Let us know if you have any other feedback, as you try out Dgraph.