MCPcopy
hub / github.com/dgraph-io/dgraph / AsString

Function AsString

graphql/dgraph/graphquery.go:19–48  ·  view source on GitHub ↗

AsString writes query as an indented dql query string. AsString doesn't validate query, and so doesn't return an error if query is 'malformed' - it might just write something that wouldn't parse as a Dgraph query.

(queries []*dql.GraphQuery)

Source from the content-addressed store, hash-verified

17// validate query, and so doesn't return an error if query is 'malformed' - it might
18// just write something that wouldn't parse as a Dgraph query.
19func AsString(queries []*dql.GraphQuery) string {
20 if len(queries) == 0 {
21 return ""
22 }
23
24 var b strings.Builder
25 queryName := queries[len(queries)-1].Attr
26 x.Check2(b.WriteString("query "))
27 addQueryVars(&b, queryName, queries[0].Args)
28 x.Check2(b.WriteString("{\n"))
29
30 numRewrittenQueries := 0
31 for _, q := range queries {
32 if q == nil {
33 // Don't call writeQuery on a nil query
34 continue
35 }
36 writeQuery(&b, q, " ")
37 numRewrittenQueries++
38 }
39 x.Check2(b.WriteString("}"))
40
41 if numRewrittenQueries == 0 {
42 // In case writeQuery has not been called on any query or all queries
43 // are nil. Then, return empty string. This case needs to be considered as
44 // we don't want to return query{} in this case.
45 return ""
46 }
47 return b.String()
48}
49
50func addQueryVars(b *strings.Builder, queryName string, args map[string]string) {
51 dollarFound := false

Callers 10

rewriteAndExecuteMethod · 0.92
deleteMutationRewritingFunction · 0.92
mutationRewritingFunction · 0.92
queryRewritingFunction · 0.92
mutationQueryRewritingFunction · 0.92
deleteQueryRewritingFunction · 0.92
TestQueryRewritingFunction · 0.92
rewriteAndExecuteMethod · 0.92
authorizeNewNodesFunction · 0.92

Calls 4

Check2Function · 0.92
addQueryVarsFunction · 0.85
writeQueryFunction · 0.85
StringMethod · 0.45

Tested by 7

deleteMutationRewritingFunction · 0.74
mutationRewritingFunction · 0.74
queryRewritingFunction · 0.74
mutationQueryRewritingFunction · 0.74
deleteQueryRewritingFunction · 0.74
TestQueryRewritingFunction · 0.74