Skip to content

Commit 0a3e314

Browse files
andrisakmlipscombe
authored andcommitted
Make sure connectByIds and deleteByIds are not processed as updateByIds (mlipscombe#4)
* Make sure connectByIds and deleteByIds, are not processed as updateByIds * Bump version
1 parent db17f9a commit 0a3e314

File tree

3 files changed

+176
-1
lines changed

3 files changed

+176
-1
lines changed

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,103 @@ GraphQLSchema {
18661866
}
18671867
`;
18681868

1869+
exports[`forward nested mutation with updateById and deleteById succeeds 1`] = `
1870+
GraphQLSchema {
1871+
"__validationErrors": Array [],
1872+
"_directives": Array [
1873+
"@include",
1874+
"@skip",
1875+
"@deprecated",
1876+
"@specifiedBy",
1877+
],
1878+
"_implementationsMap": Object {
1879+
"Node": Object {
1880+
"interfaces": Array [],
1881+
"objects": Array [
1882+
"Query",
1883+
"Child",
1884+
"Parent",
1885+
],
1886+
},
1887+
},
1888+
"_mutationType": "Mutation",
1889+
"_queryType": "Query",
1890+
"_subTypeMap": Object {},
1891+
"_subscriptionType": undefined,
1892+
"_typeMap": Object {
1893+
"Boolean": "Boolean",
1894+
"Child": "Child",
1895+
"ChildChildPkeyConnect": "ChildChildPkeyConnect",
1896+
"ChildChildPkeyDelete": "ChildChildPkeyDelete",
1897+
"ChildCondition": "ChildCondition",
1898+
"ChildInput": "ChildInput",
1899+
"ChildNodeIdConnect": "ChildNodeIdConnect",
1900+
"ChildNodeIdDelete": "ChildNodeIdDelete",
1901+
"ChildOnChildForChildParentFkeyNodeIdUpdate": "ChildOnChildForChildParentFkeyNodeIdUpdate",
1902+
"ChildOnChildForChildParentFkeyUsingChildPkeyUpdate": "ChildOnChildForChildParentFkeyUsingChildPkeyUpdate",
1903+
"ChildParentFkeyChildCreateInput": "ChildParentFkeyChildCreateInput",
1904+
"ChildParentFkeyInput": "ChildParentFkeyInput",
1905+
"ChildParentFkeyInverseInput": "ChildParentFkeyInverseInput",
1906+
"ChildParentFkeyParentCreateInput": "ChildParentFkeyParentCreateInput",
1907+
"ChildPatch": "ChildPatch",
1908+
"ChildrenConnection": "ChildrenConnection",
1909+
"ChildrenEdge": "ChildrenEdge",
1910+
"ChildrenOrderBy": "ChildrenOrderBy",
1911+
"CreateChildInput": "CreateChildInput",
1912+
"CreateChildPayload": "CreateChildPayload",
1913+
"CreateParentInput": "CreateParentInput",
1914+
"CreateParentPayload": "CreateParentPayload",
1915+
"Cursor": "Cursor",
1916+
"DeleteChildByIdInput": "DeleteChildByIdInput",
1917+
"DeleteChildInput": "DeleteChildInput",
1918+
"DeleteChildPayload": "DeleteChildPayload",
1919+
"DeleteParentByIdInput": "DeleteParentByIdInput",
1920+
"DeleteParentInput": "DeleteParentInput",
1921+
"DeleteParentPayload": "DeleteParentPayload",
1922+
"ID": "ID",
1923+
"Int": "Int",
1924+
"Mutation": "Mutation",
1925+
"Node": "Node",
1926+
"PageInfo": "PageInfo",
1927+
"Parent": "Parent",
1928+
"ParentCondition": "ParentCondition",
1929+
"ParentInput": "ParentInput",
1930+
"ParentNodeIdConnect": "ParentNodeIdConnect",
1931+
"ParentNodeIdDelete": "ParentNodeIdDelete",
1932+
"ParentOnChildForChildParentFkeyNodeIdUpdate": "ParentOnChildForChildParentFkeyNodeIdUpdate",
1933+
"ParentOnChildForChildParentFkeyUsingParentPkeyUpdate": "ParentOnChildForChildParentFkeyUsingParentPkeyUpdate",
1934+
"ParentParentPkeyConnect": "ParentParentPkeyConnect",
1935+
"ParentParentPkeyDelete": "ParentParentPkeyDelete",
1936+
"ParentPatch": "ParentPatch",
1937+
"ParentsConnection": "ParentsConnection",
1938+
"ParentsEdge": "ParentsEdge",
1939+
"ParentsOrderBy": "ParentsOrderBy",
1940+
"Query": "Query",
1941+
"String": "String",
1942+
"UpdateChildByIdInput": "UpdateChildByIdInput",
1943+
"UpdateChildInput": "UpdateChildInput",
1944+
"UpdateChildPayload": "UpdateChildPayload",
1945+
"UpdateParentByIdInput": "UpdateParentByIdInput",
1946+
"UpdateParentInput": "UpdateParentInput",
1947+
"UpdateParentPayload": "UpdateParentPayload",
1948+
"__Directive": "__Directive",
1949+
"__DirectiveLocation": "__DirectiveLocation",
1950+
"__EnumValue": "__EnumValue",
1951+
"__Field": "__Field",
1952+
"__InputValue": "__InputValue",
1953+
"__Schema": "__Schema",
1954+
"__Type": "__Type",
1955+
"__TypeKind": "__TypeKind",
1956+
"updateChildOnChildForChildParentFkeyPatch": "updateChildOnChildForChildParentFkeyPatch",
1957+
"updateParentOnChildForChildParentFkeyPatch": "updateParentOnChildForChildParentFkeyPatch",
1958+
},
1959+
"astNode": undefined,
1960+
"description": undefined,
1961+
"extensionASTNodes": undefined,
1962+
"extensions": undefined,
1963+
}
1964+
`;
1965+
18691966
exports[`reverse deeply nested mutation with nested updateById 1`] = `
18701967
GraphQLSchema {
18711968
"__validationErrors": Array [],

__tests__/integration/update.test.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,3 +1919,78 @@ test(
19191919
},
19201920
}),
19211921
);
1922+
1923+
test(
1924+
'forward nested mutation with updateById and deleteById succeeds',
1925+
withSchema({
1926+
setup: `
1927+
create table p.parent (
1928+
id serial primary key,
1929+
name text not null
1930+
);
1931+
create table p.child (
1932+
id serial primary key,
1933+
parent_id integer,
1934+
name text not null,
1935+
constraint child_parent_fkey foreign key (parent_id)
1936+
references p.parent (id)
1937+
);
1938+
1939+
insert into p.parent values(1, 'parent');
1940+
insert into p.child values(1, 1, 'child to update');
1941+
insert into p.child values(2, 1, 'child to delete');
1942+
`,
1943+
test: async ({ schema, pgClient }) => {
1944+
const newChildName = 'updated child';
1945+
1946+
const query = `
1947+
mutation {
1948+
updateParentById(
1949+
input: {
1950+
id: 1
1951+
parentPatch: {
1952+
childrenUsingId: {
1953+
deleteById: {
1954+
id: 2
1955+
}
1956+
updateById: {
1957+
id: 1
1958+
childPatch: {
1959+
name: "${newChildName}"
1960+
}
1961+
}
1962+
}
1963+
}
1964+
}
1965+
) {
1966+
parent {
1967+
id
1968+
name
1969+
childrenByParentId {
1970+
nodes {
1971+
id
1972+
parentId
1973+
name
1974+
}
1975+
}
1976+
}
1977+
}
1978+
}
1979+
`;
1980+
expect(schema).toMatchSnapshot();
1981+
1982+
const result = await graphql(schema, query, null, { pgClient });
1983+
expect(result).not.toHaveProperty('errors');
1984+
1985+
const { parent } = result.data.updateParentById;
1986+
expect(parent.childrenByParentId.nodes).toHaveLength(1);
1987+
expect(parent.id).toBe(1);
1988+
expect(parent.name).toBe('parent');
1989+
1990+
const child = parent.childrenByParentId.nodes[0];
1991+
expect(child.id).toBe(1);
1992+
expect(child.name).toBe(newChildName);
1993+
expect(child.parentId).toBe(1);
1994+
},
1995+
}),
1996+
);

src/PostgraphileNestedMutationsPlugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ module.exports = function PostGraphileNestedMutationPlugin(builder) {
457457
);
458458
}
459459

460+
// perform nested connects
460461
await Promise.all(
461462
pgNestedTableConnectorFields[foreignTable.id]
462463
.filter((f) => fieldValue[f.fieldName])
@@ -494,6 +495,7 @@ module.exports = function PostGraphileNestedMutationPlugin(builder) {
494495
}),
495496
);
496497

498+
// perform nested deletes
497499
await Promise.all(
498500
pgNestedTableDeleterFields[foreignTable.id]
499501
.filter((f) => fieldValue[f.fieldName])
@@ -518,6 +520,7 @@ module.exports = function PostGraphileNestedMutationPlugin(builder) {
518520
}),
519521
);
520522

523+
// perform nested updates
521524
await Promise.all(
522525
pgNestedTableUpdaterFields[table.id][constraint.id]
523526
.filter((f) => fieldValue[f.fieldName])
@@ -653,7 +656,7 @@ module.exports = function PostGraphileNestedMutationPlugin(builder) {
653656

654657
if (fieldValue.updateById || fieldValue.updateByNodeId) {
655658
await Promise.all(
656-
Object.keys(fieldValue)
659+
['updateById', 'updateByNodeId']
657660
.filter((f) => fieldValue[f])
658661
.map(async (f) => {
659662
await Promise.all(

0 commit comments

Comments
 (0)