Skip to content

Commit db17f9a

Browse files
andrisakmlipscombe
authored andcommitted
Add more cases to tests
1 parent ae7a3f1 commit db17f9a

File tree

3 files changed

+236
-0
lines changed

3 files changed

+236
-0
lines changed

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,103 @@ GraphQLSchema {
14781478
}
14791479
`;
14801480

1481+
exports[`forward nested mutation with create and empty nested fields succeeds 1`] = `
1482+
GraphQLSchema {
1483+
"__validationErrors": Array [],
1484+
"_directives": Array [
1485+
"@include",
1486+
"@skip",
1487+
"@deprecated",
1488+
"@specifiedBy",
1489+
],
1490+
"_implementationsMap": Object {
1491+
"Node": Object {
1492+
"interfaces": Array [],
1493+
"objects": Array [
1494+
"Query",
1495+
"Child",
1496+
"Parent",
1497+
],
1498+
},
1499+
},
1500+
"_mutationType": "Mutation",
1501+
"_queryType": "Query",
1502+
"_subTypeMap": Object {},
1503+
"_subscriptionType": undefined,
1504+
"_typeMap": Object {
1505+
"Boolean": "Boolean",
1506+
"Child": "Child",
1507+
"ChildChildPkeyConnect": "ChildChildPkeyConnect",
1508+
"ChildChildPkeyDelete": "ChildChildPkeyDelete",
1509+
"ChildCondition": "ChildCondition",
1510+
"ChildInput": "ChildInput",
1511+
"ChildNodeIdConnect": "ChildNodeIdConnect",
1512+
"ChildNodeIdDelete": "ChildNodeIdDelete",
1513+
"ChildOnChildForChildParentFkeyNodeIdUpdate": "ChildOnChildForChildParentFkeyNodeIdUpdate",
1514+
"ChildOnChildForChildParentFkeyUsingChildPkeyUpdate": "ChildOnChildForChildParentFkeyUsingChildPkeyUpdate",
1515+
"ChildParentFkeyChildCreateInput": "ChildParentFkeyChildCreateInput",
1516+
"ChildParentFkeyInput": "ChildParentFkeyInput",
1517+
"ChildParentFkeyInverseInput": "ChildParentFkeyInverseInput",
1518+
"ChildParentFkeyParentCreateInput": "ChildParentFkeyParentCreateInput",
1519+
"ChildPatch": "ChildPatch",
1520+
"ChildrenConnection": "ChildrenConnection",
1521+
"ChildrenEdge": "ChildrenEdge",
1522+
"ChildrenOrderBy": "ChildrenOrderBy",
1523+
"CreateChildInput": "CreateChildInput",
1524+
"CreateChildPayload": "CreateChildPayload",
1525+
"CreateParentInput": "CreateParentInput",
1526+
"CreateParentPayload": "CreateParentPayload",
1527+
"Cursor": "Cursor",
1528+
"DeleteChildByIdInput": "DeleteChildByIdInput",
1529+
"DeleteChildInput": "DeleteChildInput",
1530+
"DeleteChildPayload": "DeleteChildPayload",
1531+
"DeleteParentByIdInput": "DeleteParentByIdInput",
1532+
"DeleteParentInput": "DeleteParentInput",
1533+
"DeleteParentPayload": "DeleteParentPayload",
1534+
"ID": "ID",
1535+
"Int": "Int",
1536+
"Mutation": "Mutation",
1537+
"Node": "Node",
1538+
"PageInfo": "PageInfo",
1539+
"Parent": "Parent",
1540+
"ParentCondition": "ParentCondition",
1541+
"ParentInput": "ParentInput",
1542+
"ParentNodeIdConnect": "ParentNodeIdConnect",
1543+
"ParentNodeIdDelete": "ParentNodeIdDelete",
1544+
"ParentOnChildForChildParentFkeyNodeIdUpdate": "ParentOnChildForChildParentFkeyNodeIdUpdate",
1545+
"ParentOnChildForChildParentFkeyUsingParentPkeyUpdate": "ParentOnChildForChildParentFkeyUsingParentPkeyUpdate",
1546+
"ParentParentPkeyConnect": "ParentParentPkeyConnect",
1547+
"ParentParentPkeyDelete": "ParentParentPkeyDelete",
1548+
"ParentPatch": "ParentPatch",
1549+
"ParentsConnection": "ParentsConnection",
1550+
"ParentsEdge": "ParentsEdge",
1551+
"ParentsOrderBy": "ParentsOrderBy",
1552+
"Query": "Query",
1553+
"String": "String",
1554+
"UpdateChildByIdInput": "UpdateChildByIdInput",
1555+
"UpdateChildInput": "UpdateChildInput",
1556+
"UpdateChildPayload": "UpdateChildPayload",
1557+
"UpdateParentByIdInput": "UpdateParentByIdInput",
1558+
"UpdateParentInput": "UpdateParentInput",
1559+
"UpdateParentPayload": "UpdateParentPayload",
1560+
"__Directive": "__Directive",
1561+
"__DirectiveLocation": "__DirectiveLocation",
1562+
"__EnumValue": "__EnumValue",
1563+
"__Field": "__Field",
1564+
"__InputValue": "__InputValue",
1565+
"__Schema": "__Schema",
1566+
"__Type": "__Type",
1567+
"__TypeKind": "__TypeKind",
1568+
"updateChildOnChildForChildParentFkeyPatch": "updateChildOnChildForChildParentFkeyPatch",
1569+
"updateParentOnChildForChildParentFkeyPatch": "updateParentOnChildForChildParentFkeyPatch",
1570+
},
1571+
"astNode": undefined,
1572+
"description": undefined,
1573+
"extensionASTNodes": undefined,
1574+
"extensions": undefined,
1575+
}
1576+
`;
1577+
14811578
exports[`forward nested mutation with nested update 1`] = `
14821579
GraphQLSchema {
14831580
"__validationErrors": Array [],

__tests__/integration/create.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ test(
124124
name: "test f1"
125125
childrenUsingId: {
126126
create: null
127+
connectByNodeId: null
127128
connectById: null
129+
deleteByNodeId: null
130+
deleteById: null
131+
updateByNodeId: null
128132
updateById: null
129133
}
130134
}
@@ -155,6 +159,69 @@ test(
155159
}),
156160
);
157161

162+
test(
163+
'forward nested mutation with empty nested fields succeeds',
164+
withSchema({
165+
setup: `
166+
create table p.parent (
167+
id serial primary key,
168+
name text not null
169+
);
170+
171+
create table p.child (
172+
id serial primary key,
173+
parent_id integer,
174+
name text not null,
175+
constraint child_parent_fkey foreign key (parent_id)
176+
references p.parent (id)
177+
);
178+
179+
insert into p.child values(1, null, 'test child 1');
180+
`,
181+
test: async ({ schema, pgClient }) => {
182+
const query = `
183+
mutation {
184+
createParent(
185+
input: {
186+
parent: {
187+
name: "test f1"
188+
childrenUsingId: {
189+
create: []
190+
connectByNodeId: []
191+
connectById: []
192+
deleteByNodeId: []
193+
deleteById: []
194+
updateByNodeId: []
195+
updateById: []
196+
}
197+
}
198+
}
199+
) {
200+
parent {
201+
id
202+
name
203+
childrenByParentId {
204+
nodes {
205+
id
206+
parentId
207+
name
208+
}
209+
}
210+
}
211+
}
212+
}
213+
`;
214+
expect(schema).toMatchSnapshot();
215+
216+
const result = await graphql(schema, query, null, { pgClient });
217+
expect(result).not.toHaveProperty('errors');
218+
219+
const data = result.data.createParent.parent;
220+
expect(data.childrenByParentId.nodes).toHaveLength(0);
221+
},
222+
}),
223+
);
224+
158225
test(
159226
'forward nested mutation with null outer nested field succeeds',
160227
withSchema({

__tests__/integration/update.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,3 +1847,75 @@ test(
18471847
},
18481848
}),
18491849
);
1850+
1851+
test(
1852+
'forward nested mutation with create and empty nested fields succeeds',
1853+
withSchema({
1854+
setup: `
1855+
create table p.parent (
1856+
id serial primary key,
1857+
name text not null
1858+
);
1859+
create table p.child (
1860+
id serial primary key,
1861+
parent_id integer,
1862+
name text not null,
1863+
constraint child_parent_fkey foreign key (parent_id)
1864+
references p.parent (id)
1865+
);
1866+
insert into p.parent values(1, 'parent');
1867+
`,
1868+
test: async ({ schema, pgClient }) => {
1869+
const query = `
1870+
mutation {
1871+
updateParentById(
1872+
input: {
1873+
id: 1
1874+
parentPatch: {
1875+
childrenUsingId: {
1876+
create: {
1877+
id: 1,
1878+
parentId: 1,
1879+
name: "child"
1880+
},
1881+
connectByNodeId: []
1882+
connectById: []
1883+
deleteByNodeId: []
1884+
deleteById: []
1885+
updateByNodeId: []
1886+
updateById: []
1887+
}
1888+
}
1889+
}
1890+
) {
1891+
parent {
1892+
id
1893+
name
1894+
childrenByParentId {
1895+
nodes {
1896+
id
1897+
parentId
1898+
name
1899+
}
1900+
}
1901+
}
1902+
}
1903+
}
1904+
`;
1905+
expect(schema).toMatchSnapshot();
1906+
1907+
const result = await graphql(schema, query, null, { pgClient });
1908+
expect(result).not.toHaveProperty('errors');
1909+
1910+
const { parent } = result.data.updateParentById;
1911+
expect(parent.childrenByParentId.nodes).toHaveLength(1);
1912+
expect(parent.id).toBe(1);
1913+
expect(parent.name).toBe('parent');
1914+
1915+
const child = parent.childrenByParentId.nodes[0];
1916+
expect(child.id).toBe(1);
1917+
expect(child.name).toBe('child');
1918+
expect(child.parentId).toBe(1);
1919+
},
1920+
}),
1921+
);

0 commit comments

Comments
 (0)