MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TestQueryRewriting

Function TestQueryRewriting

graphql/resolve/query_test.go:37–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestQueryRewriting(t *testing.T) {
38 b, err := os.ReadFile("query_test.yaml")
39 require.NoError(t, err, "Unable to read test file")
40
41 var tests []QueryRewritingCase
42 err = yaml.Unmarshal(b, &tests)
43 require.NoError(t, err, "Unable to unmarshal tests to yaml.")
44
45 gqlSchema := test.LoadSchemaFromFile(t, "schema.graphql")
46
47 testRewriter := NewQueryRewriter()
48
49 for _, tcase := range tests {
50 t.Run(tcase.Name, func(t *testing.T) {
51 var vars map[string]interface{}
52 if tcase.GQLVariables != "" {
53 require.NoError(t, json.Unmarshal([]byte(tcase.GQLVariables), &vars))
54 }
55 op, err := gqlSchema.Operation(
56 &schema.Request{
57 Query: tcase.GQLQuery,
58 Variables: vars,
59 })
60 require.NoError(t, err)
61 gqlQuery := test.GetQuery(t, op)
62
63 dgQuery, dgVars, err := testRewriter.Rewrite(context.Background(), gqlQuery)
64 require.NoError(t, err)
65 require.Equal(t, tcase.DGQuery, dgraph.AsString(dgQuery))
66 if len(tcase.DGVars) == 0 {
67 require.Empty(t, dgVars)
68 } else {
69 require.Equal(t, tcase.DGVars, dgVars)
70 }
71 })
72 }
73}
74
75type HTTPRewritingCase struct {
76 Name string

Callers

nothing calls this directly

Calls 7

RewriteMethod · 0.95
LoadSchemaFromFileFunction · 0.92
GetQueryFunction · 0.92
AsStringFunction · 0.92
NewQueryRewriterFunction · 0.85
OperationMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected