Skip to content

Commit a705179

Browse files
committed
Add test cases for mlipscombe#31 and mlipscombe#33
1 parent af2b417 commit a705179

File tree

3 files changed

+292
-0
lines changed

3 files changed

+292
-0
lines changed

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

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,132 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`deleteBy works 1`] = `
4+
GraphQLSchema {
5+
"__validationErrors": Array [],
6+
"_directives": Array [
7+
"@include",
8+
"@skip",
9+
"@deprecated",
10+
"@specifiedBy",
11+
],
12+
"_implementationsMap": Object {
13+
"Node": Object {
14+
"interfaces": Array [],
15+
"objects": Array [
16+
"Query",
17+
"A",
18+
"AB",
19+
"B",
20+
],
21+
},
22+
},
23+
"_mutationType": "Mutation",
24+
"_queryType": "Query",
25+
"_subTypeMap": Object {},
26+
"_subscriptionType": undefined,
27+
"_typeMap": Object {
28+
"A": "A",
29+
"AAPkeyConnect": "AAPkeyConnect",
30+
"AAPkeyDelete": "AAPkeyDelete",
31+
"AB": "AB",
32+
"ABABPkeyConnect": "ABABPkeyConnect",
33+
"ABABPkeyDelete": "ABABPkeyDelete",
34+
"ABAIdFkeyABCreateInput": "ABAIdFkeyABCreateInput",
35+
"ABAIdFkeyACreateInput": "ABAIdFkeyACreateInput",
36+
"ABAIdFkeyInput": "ABAIdFkeyInput",
37+
"ABAIdFkeyInverseInput": "ABAIdFkeyInverseInput",
38+
"ABBIdFkeyABCreateInput": "ABBIdFkeyABCreateInput",
39+
"ABBIdFkeyBCreateInput": "ABBIdFkeyBCreateInput",
40+
"ABBIdFkeyInput": "ABBIdFkeyInput",
41+
"ABBIdFkeyInverseInput": "ABBIdFkeyInverseInput",
42+
"ABNodeIdConnect": "ABNodeIdConnect",
43+
"ABNodeIdDelete": "ABNodeIdDelete",
44+
"ABOnABForABAIdFkeyNodeIdUpdate": "ABOnABForABAIdFkeyNodeIdUpdate",
45+
"ABOnABForABAIdFkeyUsingABPkeyUpdate": "ABOnABForABAIdFkeyUsingABPkeyUpdate",
46+
"ABOnABForABBIdFkeyNodeIdUpdate": "ABOnABForABBIdFkeyNodeIdUpdate",
47+
"ABOnABForABBIdFkeyUsingABPkeyUpdate": "ABOnABForABBIdFkeyUsingABPkeyUpdate",
48+
"ACondition": "ACondition",
49+
"AInput": "AInput",
50+
"ANodeIdConnect": "ANodeIdConnect",
51+
"ANodeIdDelete": "ANodeIdDelete",
52+
"AOnABForABAIdFkeyNodeIdUpdate": "AOnABForABAIdFkeyNodeIdUpdate",
53+
"AOnABForABAIdFkeyUsingAPkeyUpdate": "AOnABForABAIdFkeyUsingAPkeyUpdate",
54+
"APatch": "APatch",
55+
"AbCondition": "AbCondition",
56+
"AbInput": "AbInput",
57+
"AbPatch": "AbPatch",
58+
"AbsConnection": "AbsConnection",
59+
"AbsEdge": "AbsEdge",
60+
"AbsOrderBy": "AbsOrderBy",
61+
"AsConnection": "AsConnection",
62+
"AsEdge": "AsEdge",
63+
"AsOrderBy": "AsOrderBy",
64+
"B": "B",
65+
"BBPkeyConnect": "BBPkeyConnect",
66+
"BBPkeyDelete": "BBPkeyDelete",
67+
"BCondition": "BCondition",
68+
"BInput": "BInput",
69+
"BNodeIdConnect": "BNodeIdConnect",
70+
"BNodeIdDelete": "BNodeIdDelete",
71+
"BOnABForABBIdFkeyNodeIdUpdate": "BOnABForABBIdFkeyNodeIdUpdate",
72+
"BOnABForABBIdFkeyUsingBPkeyUpdate": "BOnABForABBIdFkeyUsingBPkeyUpdate",
73+
"BPatch": "BPatch",
74+
"Boolean": "Boolean",
75+
"BsConnection": "BsConnection",
76+
"BsEdge": "BsEdge",
77+
"BsOrderBy": "BsOrderBy",
78+
"CreateABInput": "CreateABInput",
79+
"CreateABPayload": "CreateABPayload",
80+
"CreateAInput": "CreateAInput",
81+
"CreateAPayload": "CreateAPayload",
82+
"CreateBInput": "CreateBInput",
83+
"CreateBPayload": "CreateBPayload",
84+
"Cursor": "Cursor",
85+
"DeleteABByAIdAndBIdInput": "DeleteABByAIdAndBIdInput",
86+
"DeleteABInput": "DeleteABInput",
87+
"DeleteABPayload": "DeleteABPayload",
88+
"DeleteAByAIdInput": "DeleteAByAIdInput",
89+
"DeleteAInput": "DeleteAInput",
90+
"DeleteAPayload": "DeleteAPayload",
91+
"DeleteBByBIdInput": "DeleteBByBIdInput",
92+
"DeleteBInput": "DeleteBInput",
93+
"DeleteBPayload": "DeleteBPayload",
94+
"ID": "ID",
95+
"Int": "Int",
96+
"Mutation": "Mutation",
97+
"Node": "Node",
98+
"PageInfo": "PageInfo",
99+
"Query": "Query",
100+
"String": "String",
101+
"UpdateABByAIdAndBIdInput": "UpdateABByAIdAndBIdInput",
102+
"UpdateABInput": "UpdateABInput",
103+
"UpdateABPayload": "UpdateABPayload",
104+
"UpdateAByAIdInput": "UpdateAByAIdInput",
105+
"UpdateAInput": "UpdateAInput",
106+
"UpdateAPayload": "UpdateAPayload",
107+
"UpdateBByBIdInput": "UpdateBByBIdInput",
108+
"UpdateBInput": "UpdateBInput",
109+
"UpdateBPayload": "UpdateBPayload",
110+
"__Directive": "__Directive",
111+
"__DirectiveLocation": "__DirectiveLocation",
112+
"__EnumValue": "__EnumValue",
113+
"__Field": "__Field",
114+
"__InputValue": "__InputValue",
115+
"__Schema": "__Schema",
116+
"__Type": "__Type",
117+
"__TypeKind": "__TypeKind",
118+
"updateABOnABForABAIdFkeyPatch": "updateABOnABForABAIdFkeyPatch",
119+
"updateABOnABForABBIdFkeyPatch": "updateABOnABForABBIdFkeyPatch",
120+
"updateAOnABForABAIdFkeyPatch": "updateAOnABForABAIdFkeyPatch",
121+
"updateBOnABForABBIdFkeyPatch": "updateBOnABForABBIdFkeyPatch",
122+
},
123+
"astNode": undefined,
124+
"description": undefined,
125+
"extensionASTNodes": undefined,
126+
"extensions": undefined,
127+
}
128+
`;
129+
3130
exports[`forward deeply nested mutation creates records 1`] = `
4131
GraphQLSchema {
5132
"__validationErrors": Array [],
@@ -1347,3 +1474,75 @@ GraphQLSchema {
13471474
"extensions": undefined,
13481475
}
13491476
`;
1477+
1478+
exports[`works with tables that relate to themselves - child > parent 1`] = `
1479+
GraphQLSchema {
1480+
"__validationErrors": Array [],
1481+
"_directives": Array [
1482+
"@include",
1483+
"@skip",
1484+
"@deprecated",
1485+
"@specifiedBy",
1486+
],
1487+
"_implementationsMap": Object {
1488+
"Node": Object {
1489+
"interfaces": Array [],
1490+
"objects": Array [
1491+
"Query",
1492+
"Person",
1493+
],
1494+
},
1495+
},
1496+
"_mutationType": "Mutation",
1497+
"_queryType": "Query",
1498+
"_subTypeMap": Object {},
1499+
"_subscriptionType": undefined,
1500+
"_typeMap": Object {
1501+
"Boolean": "Boolean",
1502+
"CreatePersonInput": "CreatePersonInput",
1503+
"CreatePersonPayload": "CreatePersonPayload",
1504+
"Cursor": "Cursor",
1505+
"DeletePersonByIdInput": "DeletePersonByIdInput",
1506+
"DeletePersonInput": "DeletePersonInput",
1507+
"DeletePersonPayload": "DeletePersonPayload",
1508+
"ID": "ID",
1509+
"Int": "Int",
1510+
"Mutation": "Mutation",
1511+
"Node": "Node",
1512+
"PageInfo": "PageInfo",
1513+
"PeopleConnection": "PeopleConnection",
1514+
"PeopleEdge": "PeopleEdge",
1515+
"PeopleOrderBy": "PeopleOrderBy",
1516+
"Person": "Person",
1517+
"PersonCondition": "PersonCondition",
1518+
"PersonInput": "PersonInput",
1519+
"PersonNodeIdConnect": "PersonNodeIdConnect",
1520+
"PersonNodeIdDelete": "PersonNodeIdDelete",
1521+
"PersonOnPersonForPersonParentFkeyNodeIdUpdate": "PersonOnPersonForPersonParentFkeyNodeIdUpdate",
1522+
"PersonOnPersonForPersonParentFkeyUsingPersonPkeyUpdate": "PersonOnPersonForPersonParentFkeyUsingPersonPkeyUpdate",
1523+
"PersonParentFkeyInput": "PersonParentFkeyInput",
1524+
"PersonParentFkeyPersonCreateInput": "PersonParentFkeyPersonCreateInput",
1525+
"PersonPatch": "PersonPatch",
1526+
"PersonPersonPkeyConnect": "PersonPersonPkeyConnect",
1527+
"PersonPersonPkeyDelete": "PersonPersonPkeyDelete",
1528+
"Query": "Query",
1529+
"String": "String",
1530+
"UpdatePersonByIdInput": "UpdatePersonByIdInput",
1531+
"UpdatePersonInput": "UpdatePersonInput",
1532+
"UpdatePersonPayload": "UpdatePersonPayload",
1533+
"__Directive": "__Directive",
1534+
"__DirectiveLocation": "__DirectiveLocation",
1535+
"__EnumValue": "__EnumValue",
1536+
"__Field": "__Field",
1537+
"__InputValue": "__InputValue",
1538+
"__Schema": "__Schema",
1539+
"__Type": "__Type",
1540+
"__TypeKind": "__TypeKind",
1541+
"updatePersonOnPersonForPersonParentFkeyPatch": "updatePersonOnPersonForPersonParentFkeyPatch",
1542+
},
1543+
"astNode": undefined,
1544+
"description": undefined,
1545+
"extensionASTNodes": undefined,
1546+
"extensions": undefined,
1547+
}
1548+
`;

__tests__/integration/create.test.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,3 +885,95 @@ test(
885885
},
886886
}),
887887
);
888+
889+
// https://github.com/mlipscombe/postgraphile-plugin-nested-mutations/issues/33
890+
test(
891+
'works with tables that relate to themselves - child > parent',
892+
withSchema({
893+
setup: `
894+
create table p.person (
895+
id serial primary key,
896+
parent_id integer,
897+
name text not null,
898+
constraint person_parent_fkey foreign key (parent_id)
899+
references p.person(id)
900+
);
901+
`,
902+
test: async ({ schema, pgClient }) => {
903+
const query = `
904+
mutation {
905+
createPerson(
906+
input: {
907+
person: {
908+
name: "test child"
909+
personToParentId: {
910+
create: {
911+
name: "test parent"
912+
personToParentId: {
913+
create: {
914+
name: "test parent of parent"
915+
}
916+
}
917+
}
918+
}
919+
}
920+
}
921+
) {
922+
person {
923+
id
924+
name
925+
parentId
926+
personByParentId {
927+
id
928+
name
929+
parentId
930+
personByParentId {
931+
id
932+
name
933+
parentId
934+
}
935+
}
936+
}
937+
}
938+
}
939+
`;
940+
expect(schema).toMatchSnapshot();
941+
942+
const result = await graphql(schema, query, null, { pgClient });
943+
expect(result).not.toHaveProperty('errors');
944+
945+
const data = result.data.createPerson.person;
946+
expect(data.personByParentId).toHaveProperty('id');
947+
},
948+
}),
949+
);
950+
951+
// https://github.com/mlipscombe/postgraphile-plugin-nested-mutations/issues/31
952+
test(
953+
'deleteBy works',
954+
withSchema({
955+
setup: `
956+
CREATE TABLE p.a (a_id SERIAL PRIMARY KEY, name TEXT);
957+
CREATE TABLE p.b (b_id SERIAL PRIMARY KEY, name TEXT);
958+
CREATE TABLE p.a_b (a_id INT REFERENCES p.a(a_id), b_id INT REFERENCES p.b(b_id), PRIMARY KEY (a_id, b_id));
959+
`,
960+
test: async ({ schema, pgClient }) => {
961+
const query = `
962+
mutation {
963+
createA(
964+
input: { a: { aBsUsingAId: { deleteByAIdAndBId: { aId: 10, bId: 10 } } } }
965+
) {
966+
clientMutationId
967+
}
968+
}
969+
`;
970+
expect(schema).toMatchSnapshot();
971+
972+
const result = await graphql(schema, query, null, { pgClient });
973+
expect(result).not.toHaveProperty('errors');
974+
975+
// const data = result.data.createPerson.person;
976+
// expect(data.personByParentId).toHaveProperty('id');
977+
},
978+
}),
979+
);

src/PostgraphileNestedTypesPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ module.exports = function PostGraphileNestedTypesPlugin(
176176

177177
foreignKeyConstraints.forEach((constraint) => {
178178
const isForward = constraint.classId === table.id;
179+
179180
const foreignTable = isForward
180181
? introspectionResultsByKind.classById[constraint.foreignClassId]
181182
: introspectionResultsByKind.classById[constraint.classId];

0 commit comments

Comments
 (0)