Is "query" a reserved word in this context?

While looking at some of the examples on the dgo package, I came across some syntax that I do not understand. In the following query, is the word query a reserved word?

q := `query Alice($a: string){
		me(func: eq(name, $a)) {
			name
		}
	}`

I saw the same usage in other examples on the same page. What exactly is the functionality of this part of the statement: query Alice($a: string)?

Query is just a keyword for the Query block. It is not mandatory.

This is a GraphQL Variable for Dgraph. (It is not related to GraphQL feature itself).

see => Get started with Dgraph

I see. It appears that the beginning portion of the statement is the, “named query clause”. I played around with the examples a bit and it appears that query is in fact mandatory.

Good: query Alice($a: string){me(func: eq(name, $a)) {name}}
Error: Alice($a: string){me(func: eq(name, $a)) {name}}
Error: query ($a: string){me(func: eq(name, $a)) {name}}

Thank you for the reference link. This is very helpful.

It’s mandatory case you gonna use GraphQL variables or give a name to your query. Otherwise, you can go with

{ q(func: ...) {...} }

Instead of

query namequery{ q(func: ...) {...} }

1 Like