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

Function mutationQueryRewriting

graphql/resolve/auth_test.go:460–604  ·  view source on GitHub ↗

Tests that the queries that run after a mutation get auth correctly added in.

(t *testing.T, sch string, authMeta *testutil.AuthMeta)

Source from the content-addressed store, hash-verified

458
459// Tests that the queries that run after a mutation get auth correctly added in.
460func mutationQueryRewriting(t *testing.T, sch string, authMeta *testutil.AuthMeta) {
461 tests := map[string]struct {
462 gqlMut string
463 rewriter func() MutationRewriter
464 assigned map[string]string
465 idExistence map[string]string
466 result map[string]interface{}
467 dgQuery string
468 }{
469 "Add Ticket": {
470 gqlMut: `mutation {
471 addTicket(input: [{title: "A ticket", onColumn: {colID: "0x1"}}]) {
472 ticket {
473 id
474 title
475 onColumn {
476 colID
477 name
478 }
479 }
480 }
481 }`,
482 rewriter: NewAddRewriter,
483 assigned: map[string]string{"Ticket_2": "0x4"},
484 idExistence: map[string]string{"Column_1": "0x1"},
485 dgQuery: `query {
486 AddTicketPayload.ticket(func: uid(TicketRoot)) {
487 Ticket.id : uid
488 Ticket.title : Ticket.title
489 Ticket.onColumn : Ticket.onColumn @filter(uid(Column_1)) {
490 Column.colID : uid
491 Column.name : Column.name
492 }
493 }
494 TicketRoot as var(func: uid(Ticket_4)) @filter(uid(Ticket_Auth5))
495 Ticket_4 as var(func: uid(0x4))
496 Ticket_Auth5 as var(func: uid(Ticket_4)) @cascade {
497 Ticket.onColumn : Ticket.onColumn {
498 Column.inProject : Column.inProject {
499 Project.roles : Project.roles @filter(eq(Role.permission, "VIEW")) {
500 Role.assignedTo : Role.assignedTo @filter(eq(User.username, "user1"))
501 }
502 }
503 }
504 }
505 var(func: uid(TicketRoot)) {
506 Column_2 as Ticket.onColumn
507 }
508 Column_1 as var(func: uid(Column_2)) @filter(uid(Column_Auth3))
509 Column_Auth3 as var(func: uid(Column_2)) @cascade {
510 Column.inProject : Column.inProject {
511 Project.roles : Project.roles @filter(eq(Role.permission, "VIEW")) {
512 Role.assignedTo : Role.assignedTo @filter(eq(User.username, "user1"))
513 }
514 }
515 }
516}`,
517 },

Callers 1

TestAuthQueryRewritingFunction · 0.85

Calls 10

LoadSchemaFromStringFunction · 0.92
GetMutationFunction · 0.92
AsStringFunction · 0.92
ParseFunction · 0.92
AddClaimsToContextMethod · 0.80
OperationMethod · 0.65
RewriteQueriesMethod · 0.65
RewriteMethod · 0.65
FromMutationResultMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected