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

Function TestMutationQueryRewriting

graphql/resolve/mutation_test.go:307–384  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

305}
306
307func TestMutationQueryRewriting(t *testing.T) {
308 testTypes := map[string]struct {
309 mut string
310 payloadType string
311 rewriter func() MutationRewriter
312 idExistence map[string]string
313 assigned map[string]string
314 result map[string]interface{}
315 }{
316 "Add Post ": {
317 mut: `addPost(input: [{title: "A Post", author: {id: "0x1"}}])`,
318 payloadType: "AddPostPayload",
319 rewriter: NewAddRewriter,
320 idExistence: map[string]string{"Author_1": "0x1"},
321 assigned: map[string]string{"Post_2": "0x4"},
322 },
323 "Update Post ": {
324 mut: `updatePost(input: {filter: {postID
325 : ["0x4"]}, set: {text: "Updated text"} }) `,
326 payloadType: "UpdatePostPayload",
327 rewriter: NewUpdateRewriter,
328 result: map[string]interface{}{
329 "updatePost": []interface{}{map[string]interface{}{"uid": "0x4"}}},
330 },
331 }
332
333 allowedTestTypes := map[string][]string{
334 "UPDATE_MUTATION": {"Update Post "},
335 "ADD_UPDATE_MUTATION": {"Add Post ", "Update Post "},
336 }
337
338 b, err := os.ReadFile("mutation_query_test.yaml")
339 require.NoError(t, err, "Unable to read test file")
340
341 var tests map[string][]QueryRewritingCase
342 err = yaml.Unmarshal(b, &tests)
343 require.NoError(t, err, "Unable to unmarshal tests to yaml.")
344
345 gqlSchema := test.LoadSchemaFromFile(t, "schema.graphql")
346
347 for testType := range tests {
348 for _, name := range allowedTestTypes[testType] {
349 tt := testTypes[name]
350 for _, tcase := range tests[testType] {
351 t.Run(name+testType+tcase.Name, func(t *testing.T) {
352 rewriter := tt.rewriter()
353 // -- Arrange --
354 gqlMutationStr := strings.Replace(tcase.GQLQuery, testType, tt.mut, 1)
355 tcase.DGQuery = strings.Replace(tcase.DGQuery, "PAYLOAD_TYPE",
356 tt.payloadType, 1)
357 var vars map[string]interface{}
358 if tcase.GQLVariables != "" {
359 require.NoError(t, json.Unmarshal([]byte(tcase.GQLVariables), &vars))
360 }
361 op, err := gqlSchema.Operation(
362 &schema.Request{
363 Query: gqlMutationStr,
364 Variables: vars,

Callers

nothing calls this directly

Calls 8

LoadSchemaFromFileFunction · 0.92
GetMutationFunction · 0.92
AsStringFunction · 0.92
OperationMethod · 0.65
RewriteQueriesMethod · 0.65
RewriteMethod · 0.65
FromMutationResultMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected