Skip to content

Commit 5dbab8e

Browse files
committed
add test for updateByNodeId with composite primary key
1 parent 5c1ec43 commit 5dbab8e

File tree

2 files changed

+227
-62
lines changed

2 files changed

+227
-62
lines changed

__tests__/integration/__snapshots__/update.test.js.snap

Lines changed: 149 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ GraphQLSchema {
424424
}
425425
`;
426426

427-
exports[`forward nested mutation during update 2`] = `
427+
exports[`forward nested mutation with nested update 1`] = `
428428
GraphQLSchema {
429429
"__allowedLegacyNames": Array [],
430430
"__validationErrors": undefined,
@@ -436,72 +436,66 @@ GraphQLSchema {
436436
"_implementations": Object {
437437
"Node": Array [
438438
"Query",
439-
"User",
440-
"UserPrivate",
439+
"Child",
440+
"Parent",
441441
],
442442
},
443443
"_mutationType": "Mutation",
444444
"_possibleTypeMap": undefined,
445445
"_queryType": "Query",
446446
"_subscriptionType": undefined,
447447
"_typeMap": Object {
448-
"BigInt": "BigInt",
449448
"Boolean": "Boolean",
450-
"CreateUserInput": "CreateUserInput",
451-
"CreateUserPayload": "CreateUserPayload",
452-
"CreateUserPrivateInput": "CreateUserPrivateInput",
453-
"CreateUserPrivatePayload": "CreateUserPrivatePayload",
449+
"Child": "Child",
450+
"ChildChildPkeyConnect": "ChildChildPkeyConnect",
451+
"ChildCondition": "ChildCondition",
452+
"ChildInput": "ChildInput",
453+
"ChildNodeIdConnect": "ChildNodeIdConnect",
454+
"ChildOnChildForChildParentFkeyNodeIdUpdate": "ChildOnChildForChildParentFkeyNodeIdUpdate",
455+
"ChildOnChildForChildParentFkeyUsingChildPkeyUpdate": "ChildOnChildForChildParentFkeyUsingChildPkeyUpdate",
456+
"ChildParentFkeyChildCreateInput": "ChildParentFkeyChildCreateInput",
457+
"ChildParentFkeyInput": "ChildParentFkeyInput",
458+
"ChildParentFkeyInverseInput": "ChildParentFkeyInverseInput",
459+
"ChildParentFkeyParentCreateInput": "ChildParentFkeyParentCreateInput",
460+
"ChildPatch": "ChildPatch",
461+
"ChildrenConnection": "ChildrenConnection",
462+
"ChildrenEdge": "ChildrenEdge",
463+
"ChildrenOrderBy": "ChildrenOrderBy",
464+
"CreateChildInput": "CreateChildInput",
465+
"CreateChildPayload": "CreateChildPayload",
466+
"CreateParentInput": "CreateParentInput",
467+
"CreateParentPayload": "CreateParentPayload",
454468
"Cursor": "Cursor",
455-
"DeleteUserByIdInput": "DeleteUserByIdInput",
456-
"DeleteUserByUsernameInput": "DeleteUserByUsernameInput",
457-
"DeleteUserInput": "DeleteUserInput",
458-
"DeleteUserPayload": "DeleteUserPayload",
459-
"DeleteUserPrivateByIdInput": "DeleteUserPrivateByIdInput",
460-
"DeleteUserPrivateInput": "DeleteUserPrivateInput",
461-
"DeleteUserPrivatePayload": "DeleteUserPrivatePayload",
469+
"DeleteChildByIdInput": "DeleteChildByIdInput",
470+
"DeleteChildInput": "DeleteChildInput",
471+
"DeleteChildPayload": "DeleteChildPayload",
472+
"DeleteParentByIdInput": "DeleteParentByIdInput",
473+
"DeleteParentInput": "DeleteParentInput",
474+
"DeleteParentPayload": "DeleteParentPayload",
462475
"ID": "ID",
463476
"Int": "Int",
464-
"JSON": "JSON",
465477
"Mutation": "Mutation",
466478
"Node": "Node",
467479
"PageInfo": "PageInfo",
480+
"Parent": "Parent",
481+
"ParentCondition": "ParentCondition",
482+
"ParentInput": "ParentInput",
483+
"ParentNodeIdConnect": "ParentNodeIdConnect",
484+
"ParentOnChildForChildParentFkeyNodeIdUpdate": "ParentOnChildForChildParentFkeyNodeIdUpdate",
485+
"ParentOnChildForChildParentFkeyUsingParentPkeyUpdate": "ParentOnChildForChildParentFkeyUsingParentPkeyUpdate",
486+
"ParentParentPkeyConnect": "ParentParentPkeyConnect",
487+
"ParentPatch": "ParentPatch",
488+
"ParentsConnection": "ParentsConnection",
489+
"ParentsEdge": "ParentsEdge",
490+
"ParentsOrderBy": "ParentsOrderBy",
468491
"Query": "Query",
469492
"String": "String",
470-
"UpdateUserByIdInput": "UpdateUserByIdInput",
471-
"UpdateUserByUsernameInput": "UpdateUserByUsernameInput",
472-
"UpdateUserInput": "UpdateUserInput",
473-
"UpdateUserPayload": "UpdateUserPayload",
474-
"UpdateUserPrivateByIdInput": "UpdateUserPrivateByIdInput",
475-
"UpdateUserPrivateInput": "UpdateUserPrivateInput",
476-
"UpdateUserPrivatePayload": "UpdateUserPrivatePayload",
477-
"User": "User",
478-
"UserCondition": "UserCondition",
479-
"UserInput": "UserInput",
480-
"UserNodeIdConnect": "UserNodeIdConnect",
481-
"UserOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate": "UserOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate",
482-
"UserOnUserPrivateForUserPrivateIdFkeyUsingUserPkeyUpdate": "UserOnUserPrivateForUserPrivateIdFkeyUsingUserPkeyUpdate",
483-
"UserOnUserPrivateForUserPrivateIdFkeyUsingUserUsernameKeyUpdate": "UserOnUserPrivateForUserPrivateIdFkeyUsingUserUsernameKeyUpdate",
484-
"UserPatch": "UserPatch",
485-
"UserPrivate": "UserPrivate",
486-
"UserPrivateCondition": "UserPrivateCondition",
487-
"UserPrivateIdFkeyInput": "UserPrivateIdFkeyInput",
488-
"UserPrivateIdFkeyInverseInput": "UserPrivateIdFkeyInverseInput",
489-
"UserPrivateIdFkeyUserCreateInput": "UserPrivateIdFkeyUserCreateInput",
490-
"UserPrivateIdFkeyUserPrivateCreateInput": "UserPrivateIdFkeyUserPrivateCreateInput",
491-
"UserPrivateInput": "UserPrivateInput",
492-
"UserPrivateNodeIdConnect": "UserPrivateNodeIdConnect",
493-
"UserPrivateOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate": "UserPrivateOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate",
494-
"UserPrivateOnUserPrivateForUserPrivateIdFkeyUsingUserPrivatePkeyUpdate": "UserPrivateOnUserPrivateForUserPrivateIdFkeyUsingUserPrivatePkeyUpdate",
495-
"UserPrivatePatch": "UserPrivatePatch",
496-
"UserPrivateUserPrivatePkeyConnect": "UserPrivateUserPrivatePkeyConnect",
497-
"UserPrivatesConnection": "UserPrivatesConnection",
498-
"UserPrivatesEdge": "UserPrivatesEdge",
499-
"UserPrivatesOrderBy": "UserPrivatesOrderBy",
500-
"UserUserPkeyConnect": "UserUserPkeyConnect",
501-
"UserUserUsernameKeyConnect": "UserUserUsernameKeyConnect",
502-
"UsersConnection": "UsersConnection",
503-
"UsersEdge": "UsersEdge",
504-
"UsersOrderBy": "UsersOrderBy",
493+
"UpdateChildByIdInput": "UpdateChildByIdInput",
494+
"UpdateChildInput": "UpdateChildInput",
495+
"UpdateChildPayload": "UpdateChildPayload",
496+
"UpdateParentByIdInput": "UpdateParentByIdInput",
497+
"UpdateParentInput": "UpdateParentInput",
498+
"UpdateParentPayload": "UpdateParentPayload",
505499
"__Directive": "__Directive",
506500
"__DirectiveLocation": "__DirectiveLocation",
507501
"__EnumValue": "__EnumValue",
@@ -510,15 +504,15 @@ GraphQLSchema {
510504
"__Schema": "__Schema",
511505
"__Type": "__Type",
512506
"__TypeKind": "__TypeKind",
513-
"updateUserOnUserPrivateForUserPrivateIdFkeyPatch": "updateUserOnUserPrivateForUserPrivateIdFkeyPatch",
514-
"updateUserPrivateOnUserPrivateForUserPrivateIdFkeyPatch": "updateUserPrivateOnUserPrivateForUserPrivateIdFkeyPatch",
507+
"updateChildOnChildForChildParentFkeyPatch": "updateChildOnChildForChildParentFkeyPatch",
508+
"updateParentOnChildForChildParentFkeyPatch": "updateParentOnChildForChildParentFkeyPatch",
515509
},
516510
"astNode": undefined,
517511
"extensionASTNodes": undefined,
518512
}
519513
`;
520514

521-
exports[`forward nested mutation with nested update 1`] = `
515+
exports[`forward nested mutation with nested update does not accept updates to constraint keys 1`] = `
522516
GraphQLSchema {
523517
"__allowedLegacyNames": Array [],
524518
"__validationErrors": undefined,
@@ -606,10 +600,10 @@ GraphQLSchema {
606600
}
607601
`;
608602

609-
exports[`forward nested mutation with nested update does not accept updates to constraint keys 1`] = `
603+
exports[`forward nested mutation with nested updateByNodeId 1`] = `
610604
GraphQLSchema {
611605
"__allowedLegacyNames": Array [],
612-
"__validationErrors": undefined,
606+
"__validationErrors": Array [],
613607
"_directives": Array [
614608
"@include",
615609
"@skip",
@@ -694,10 +688,10 @@ GraphQLSchema {
694688
}
695689
`;
696690

697-
exports[`forward nested mutation with nested updateByNodeId 1`] = `
691+
exports[`reverse nested mutation with nested update 1`] = `
698692
GraphQLSchema {
699693
"__allowedLegacyNames": Array [],
700-
"__validationErrors": Array [],
694+
"__validationErrors": undefined,
701695
"_directives": Array [
702696
"@include",
703697
"@skip",
@@ -782,7 +776,7 @@ GraphQLSchema {
782776
}
783777
`;
784778

785-
exports[`reverse nested mutation with nested update 1`] = `
779+
exports[`updateByNodeId does not error 1`] = `
786780
GraphQLSchema {
787781
"__allowedLegacyNames": Array [],
788782
"__validationErrors": undefined,
@@ -791,6 +785,100 @@ GraphQLSchema {
791785
"@skip",
792786
"@deprecated",
793787
],
788+
"_implementations": Object {
789+
"Node": Array [
790+
"Query",
791+
"User",
792+
"UserPrivate",
793+
],
794+
},
795+
"_mutationType": "Mutation",
796+
"_possibleTypeMap": undefined,
797+
"_queryType": "Query",
798+
"_subscriptionType": undefined,
799+
"_typeMap": Object {
800+
"BigInt": "BigInt",
801+
"Boolean": "Boolean",
802+
"CreateUserInput": "CreateUserInput",
803+
"CreateUserPayload": "CreateUserPayload",
804+
"CreateUserPrivateInput": "CreateUserPrivateInput",
805+
"CreateUserPrivatePayload": "CreateUserPrivatePayload",
806+
"Cursor": "Cursor",
807+
"DeleteUserByIdInput": "DeleteUserByIdInput",
808+
"DeleteUserByUsernameInput": "DeleteUserByUsernameInput",
809+
"DeleteUserInput": "DeleteUserInput",
810+
"DeleteUserPayload": "DeleteUserPayload",
811+
"DeleteUserPrivateByIdInput": "DeleteUserPrivateByIdInput",
812+
"DeleteUserPrivateInput": "DeleteUserPrivateInput",
813+
"DeleteUserPrivatePayload": "DeleteUserPrivatePayload",
814+
"ID": "ID",
815+
"Int": "Int",
816+
"JSON": "JSON",
817+
"Mutation": "Mutation",
818+
"Node": "Node",
819+
"PageInfo": "PageInfo",
820+
"Query": "Query",
821+
"String": "String",
822+
"UpdateUserByIdInput": "UpdateUserByIdInput",
823+
"UpdateUserByUsernameInput": "UpdateUserByUsernameInput",
824+
"UpdateUserInput": "UpdateUserInput",
825+
"UpdateUserPayload": "UpdateUserPayload",
826+
"UpdateUserPrivateByIdInput": "UpdateUserPrivateByIdInput",
827+
"UpdateUserPrivateInput": "UpdateUserPrivateInput",
828+
"UpdateUserPrivatePayload": "UpdateUserPrivatePayload",
829+
"User": "User",
830+
"UserCondition": "UserCondition",
831+
"UserInput": "UserInput",
832+
"UserNodeIdConnect": "UserNodeIdConnect",
833+
"UserOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate": "UserOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate",
834+
"UserOnUserPrivateForUserPrivateIdFkeyUsingUserPkeyUpdate": "UserOnUserPrivateForUserPrivateIdFkeyUsingUserPkeyUpdate",
835+
"UserOnUserPrivateForUserPrivateIdFkeyUsingUserUsernameKeyUpdate": "UserOnUserPrivateForUserPrivateIdFkeyUsingUserUsernameKeyUpdate",
836+
"UserPatch": "UserPatch",
837+
"UserPrivate": "UserPrivate",
838+
"UserPrivateCondition": "UserPrivateCondition",
839+
"UserPrivateIdFkeyInput": "UserPrivateIdFkeyInput",
840+
"UserPrivateIdFkeyInverseInput": "UserPrivateIdFkeyInverseInput",
841+
"UserPrivateIdFkeyUserCreateInput": "UserPrivateIdFkeyUserCreateInput",
842+
"UserPrivateIdFkeyUserPrivateCreateInput": "UserPrivateIdFkeyUserPrivateCreateInput",
843+
"UserPrivateInput": "UserPrivateInput",
844+
"UserPrivateNodeIdConnect": "UserPrivateNodeIdConnect",
845+
"UserPrivateOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate": "UserPrivateOnUserPrivateForUserPrivateIdFkeyNodeIdUpdate",
846+
"UserPrivateOnUserPrivateForUserPrivateIdFkeyUsingUserPrivatePkeyUpdate": "UserPrivateOnUserPrivateForUserPrivateIdFkeyUsingUserPrivatePkeyUpdate",
847+
"UserPrivatePatch": "UserPrivatePatch",
848+
"UserPrivateUserPrivatePkeyConnect": "UserPrivateUserPrivatePkeyConnect",
849+
"UserPrivatesConnection": "UserPrivatesConnection",
850+
"UserPrivatesEdge": "UserPrivatesEdge",
851+
"UserPrivatesOrderBy": "UserPrivatesOrderBy",
852+
"UserUserPkeyConnect": "UserUserPkeyConnect",
853+
"UserUserUsernameKeyConnect": "UserUserUsernameKeyConnect",
854+
"UsersConnection": "UsersConnection",
855+
"UsersEdge": "UsersEdge",
856+
"UsersOrderBy": "UsersOrderBy",
857+
"__Directive": "__Directive",
858+
"__DirectiveLocation": "__DirectiveLocation",
859+
"__EnumValue": "__EnumValue",
860+
"__Field": "__Field",
861+
"__InputValue": "__InputValue",
862+
"__Schema": "__Schema",
863+
"__Type": "__Type",
864+
"__TypeKind": "__TypeKind",
865+
"updateUserOnUserPrivateForUserPrivateIdFkeyPatch": "updateUserOnUserPrivateForUserPrivateIdFkeyPatch",
866+
"updateUserPrivateOnUserPrivateForUserPrivateIdFkeyPatch": "updateUserPrivateOnUserPrivateForUserPrivateIdFkeyPatch",
867+
},
868+
"astNode": undefined,
869+
"extensionASTNodes": undefined,
870+
}
871+
`;
872+
873+
exports[`updateByNodeId with composite primary key works 1`] = `
874+
GraphQLSchema {
875+
"__allowedLegacyNames": Array [],
876+
"__validationErrors": Array [],
877+
"_directives": Array [
878+
"@include",
879+
"@skip",
880+
"@deprecated",
881+
],
794882
"_implementations": Object {
795883
"Node": Array [
796884
"Query",
@@ -824,7 +912,7 @@ GraphQLSchema {
824912
"CreateParentInput": "CreateParentInput",
825913
"CreateParentPayload": "CreateParentPayload",
826914
"Cursor": "Cursor",
827-
"DeleteChildByIdInput": "DeleteChildByIdInput",
915+
"DeleteChildByIdAndParentIdAndNameInput": "DeleteChildByIdAndParentIdAndNameInput",
828916
"DeleteChildInput": "DeleteChildInput",
829917
"DeleteChildPayload": "DeleteChildPayload",
830918
"DeleteParentByIdInput": "DeleteParentByIdInput",
@@ -848,7 +936,7 @@ GraphQLSchema {
848936
"ParentsOrderBy": "ParentsOrderBy",
849937
"Query": "Query",
850938
"String": "String",
851-
"UpdateChildByIdInput": "UpdateChildByIdInput",
939+
"UpdateChildByIdAndParentIdAndNameInput": "UpdateChildByIdAndParentIdAndNameInput",
852940
"UpdateChildInput": "UpdateChildInput",
853941
"UpdateChildPayload": "UpdateChildPayload",
854942
"UpdateParentByIdInput": "UpdateParentByIdInput",

__tests__/integration/update.test.js

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,83 @@ test(
451451
}),
452452
);
453453

454+
test(
455+
'updateByNodeId with composite primary key works',
456+
withSchema({
457+
setup: `
458+
create table p.parent (
459+
id serial primary key,
460+
name text not null
461+
);
462+
463+
create table p.child (
464+
id integer not null,
465+
parent_id integer,
466+
name text not null,
467+
constraint child_pkey primary key (id, parent_id, name),
468+
constraint child_parent_fkey foreign key (parent_id)
469+
references p.parent (id)
470+
);
471+
472+
insert into p.parent values(1, 'test parent');
473+
insert into p.child values(1, 1, 'test child');
474+
`,
475+
test: async ({ schema, pgClient }) => {
476+
const lookupQuery = `
477+
query {
478+
childByIdAndParentIdAndName(id: 1, parentId: 1, name: "test child") {
479+
nodeId
480+
}
481+
}
482+
`;
483+
const lookupResult = await graphql(schema, lookupQuery, null, { pgClient });
484+
const { nodeId } = lookupResult.data.childByIdAndParentIdAndName;
485+
expect(nodeId).not.toBeUndefined();
486+
487+
const query = `
488+
mutation {
489+
updateParentById(
490+
input: {
491+
id: 1
492+
parentPatch: {
493+
childrenUsingId: {
494+
updateByNodeId: {
495+
nodeId: "${nodeId}"
496+
childPatch: {
497+
name: "renamed child"
498+
}
499+
}
500+
}
501+
}
502+
}
503+
) {
504+
parent {
505+
id
506+
name
507+
childrenByParentId {
508+
nodes {
509+
id
510+
parentId
511+
name
512+
}
513+
}
514+
}
515+
}
516+
}
517+
`;
518+
expect(schema).toMatchSnapshot();
519+
520+
const result = await graphql(schema, query, null, { pgClient });
521+
expect(result).not.toHaveProperty('errors');
522+
523+
const data = result.data.updateParentById.parent;
524+
expect(data.childrenByParentId.nodes).toHaveLength(1);
525+
data.childrenByParentId.nodes.map(n => expect(n.parentId).toBe(data.id));
526+
expect(data.childrenByParentId.nodes[0].name).toEqual('renamed child');
527+
},
528+
}),
529+
);
530+
454531
test(
455532
'reverse nested mutation with nested update',
456533
withSchema({
@@ -575,7 +652,7 @@ test(
575652
);
576653

577654
test(
578-
'forward nested mutation during update',
655+
'updateByNodeId does not error',
579656
withSchema({
580657
setup: `
581658
CREATE TABLE p."user" (

0 commit comments

Comments
 (0)