Skip to content

Commit cc82ac4

Browse files
committed
Add support for --classic-ids. Closes mlipscombe#40.
1 parent a705179 commit cc82ac4

File tree

6 files changed

+158
-6
lines changed

6 files changed

+158
-6
lines changed

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

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

3+
exports[`id fields are renamed rowId when classicIds is enabled 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+
"Child",
18+
"Parent",
19+
],
20+
},
21+
},
22+
"_mutationType": "Mutation",
23+
"_queryType": "Query",
24+
"_subTypeMap": Object {},
25+
"_subscriptionType": undefined,
26+
"_typeMap": Object {
27+
"Boolean": "Boolean",
28+
"Child": "Child",
29+
"ChildChildPkeyConnect": "ChildChildPkeyConnect",
30+
"ChildChildPkeyDelete": "ChildChildPkeyDelete",
31+
"ChildCondition": "ChildCondition",
32+
"ChildInput": "ChildInput",
33+
"ChildNodeIdConnect": "ChildNodeIdConnect",
34+
"ChildNodeIdDelete": "ChildNodeIdDelete",
35+
"ChildOnChildForChildParentIdFkeyNodeIdUpdate": "ChildOnChildForChildParentIdFkeyNodeIdUpdate",
36+
"ChildOnChildForChildParentIdFkeyUsingChildPkeyUpdate": "ChildOnChildForChildParentIdFkeyUsingChildPkeyUpdate",
37+
"ChildParentIdFkeyChildCreateInput": "ChildParentIdFkeyChildCreateInput",
38+
"ChildParentIdFkeyInput": "ChildParentIdFkeyInput",
39+
"ChildParentIdFkeyInverseInput": "ChildParentIdFkeyInverseInput",
40+
"ChildParentIdFkeyParentCreateInput": "ChildParentIdFkeyParentCreateInput",
41+
"ChildPatch": "ChildPatch",
42+
"ChildrenConnection": "ChildrenConnection",
43+
"ChildrenEdge": "ChildrenEdge",
44+
"ChildrenOrderBy": "ChildrenOrderBy",
45+
"CreateChildInput": "CreateChildInput",
46+
"CreateChildPayload": "CreateChildPayload",
47+
"CreateParentInput": "CreateParentInput",
48+
"CreateParentPayload": "CreateParentPayload",
49+
"Cursor": "Cursor",
50+
"DeleteChildByRowIdInput": "DeleteChildByRowIdInput",
51+
"DeleteChildInput": "DeleteChildInput",
52+
"DeleteChildPayload": "DeleteChildPayload",
53+
"DeleteParentByRowIdInput": "DeleteParentByRowIdInput",
54+
"DeleteParentInput": "DeleteParentInput",
55+
"DeleteParentPayload": "DeleteParentPayload",
56+
"ID": "ID",
57+
"Int": "Int",
58+
"Mutation": "Mutation",
59+
"Node": "Node",
60+
"PageInfo": "PageInfo",
61+
"Parent": "Parent",
62+
"ParentCondition": "ParentCondition",
63+
"ParentInput": "ParentInput",
64+
"ParentNodeIdConnect": "ParentNodeIdConnect",
65+
"ParentNodeIdDelete": "ParentNodeIdDelete",
66+
"ParentOnChildForChildParentIdFkeyNodeIdUpdate": "ParentOnChildForChildParentIdFkeyNodeIdUpdate",
67+
"ParentOnChildForChildParentIdFkeyUsingParentPkeyUpdate": "ParentOnChildForChildParentIdFkeyUsingParentPkeyUpdate",
68+
"ParentParentPkeyConnect": "ParentParentPkeyConnect",
69+
"ParentParentPkeyDelete": "ParentParentPkeyDelete",
70+
"ParentPatch": "ParentPatch",
71+
"ParentsConnection": "ParentsConnection",
72+
"ParentsEdge": "ParentsEdge",
73+
"ParentsOrderBy": "ParentsOrderBy",
74+
"Query": "Query",
75+
"String": "String",
76+
"UUID": "UUID",
77+
"UpdateChildByRowIdInput": "UpdateChildByRowIdInput",
78+
"UpdateChildInput": "UpdateChildInput",
79+
"UpdateChildPayload": "UpdateChildPayload",
80+
"UpdateParentByRowIdInput": "UpdateParentByRowIdInput",
81+
"UpdateParentInput": "UpdateParentInput",
82+
"UpdateParentPayload": "UpdateParentPayload",
83+
"__Directive": "__Directive",
84+
"__DirectiveLocation": "__DirectiveLocation",
85+
"__EnumValue": "__EnumValue",
86+
"__Field": "__Field",
87+
"__InputValue": "__InputValue",
88+
"__Schema": "__Schema",
89+
"__Type": "__Type",
90+
"__TypeKind": "__TypeKind",
91+
"updateChildOnChildForChildParentIdFkeyPatch": "updateChildOnChildForChildParentIdFkeyPatch",
92+
"updateParentOnChildForChildParentIdFkeyPatch": "updateParentOnChildForChildParentIdFkeyPatch",
93+
},
94+
"astNode": undefined,
95+
"description": undefined,
96+
"extensionASTNodes": undefined,
97+
"extensions": undefined,
98+
}
99+
`;
100+
3101
exports[`simple names, plural when one-to-many, singular in reverse 1`] = `
4102
GraphQLSchema {
5103
"__validationErrors": Array [],

__tests__/integration/options.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,57 @@ test(
248248
},
249249
}),
250250
);
251+
252+
// from https://github.com/mlipscombe/postgraphile-plugin-nested-mutations/issues/40
253+
test(
254+
'id fields are renamed rowId when classicIds is enabled',
255+
withSchema({
256+
setup: `
257+
create table p.parent (
258+
id uuid primary key default public.uuid_generate_v4(),
259+
name text not null
260+
);
261+
create table p.child (
262+
id uuid primary key default public.uuid_generate_v4(),
263+
parent_id uuid references p.parent on delete set null,
264+
name text not null
265+
);
266+
`,
267+
options: {
268+
classicIds: true,
269+
},
270+
test: async ({ schema, pgClient }) => {
271+
const query = `
272+
mutation {
273+
createParent(
274+
input: {
275+
parent: {
276+
name: "test"
277+
childrenUsingRowId: {
278+
create: {
279+
name: "test child"
280+
}
281+
}
282+
}
283+
}
284+
) {
285+
parent {
286+
id
287+
rowId
288+
childrenByParentId {
289+
nodes {
290+
id
291+
rowId
292+
}
293+
}
294+
}
295+
}
296+
}
297+
`;
298+
expect(schema).toMatchSnapshot();
299+
300+
const result = await graphql(schema, query, null, { pgClient });
301+
expect(result).not.toHaveProperty('errors');
302+
},
303+
}),
304+
);

src/PostgraphileNestedConnectorsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function PostGraphileNestedConnectorsPlugin(builder) {
88
const { constraint } = options;
99
return this.camelCase(
1010
`connect_by_${constraint.keyAttributes
11-
.map((k) => k.name)
11+
.map((k) => this.column(k))
1212
.join('_and_')}`,
1313
);
1414
},

src/PostgraphileNestedDeletersPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function PostGraphileNestedDeletersPlugin(builder) {
88
const { constraint } = options;
99
return this.camelCase(
1010
`delete_by_${constraint.keyAttributes
11-
.map((k) => k.name)
11+
.map((k) => this.column(k))
1212
.join('_and_')}`,
1313
);
1414
},

src/PostgraphileNestedTypesPlugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ module.exports = function PostGraphileNestedTypesPlugin(
5959
foreignTable,
6060
} = options;
6161
const tableFieldName = inflection.tableFieldName(foreignTable);
62-
const keyNames = keys.map((k) => k.name);
63-
const foreignKeyNames = foreignKeys.map((k) => k.name);
62+
const keyNames = keys.map((k) => inflection.column(k));
63+
const foreignKeyNames = foreignKeys.map((k) => inflection.column(k));
6464

6565
const constraints = foreignTable.constraints
6666
.filter((con) => con.type === 'f')
@@ -176,7 +176,7 @@ module.exports = function PostGraphileNestedTypesPlugin(
176176

177177
foreignKeyConstraints.forEach((constraint) => {
178178
const isForward = constraint.classId === table.id;
179-
179+
180180
const foreignTable = isForward
181181
? introspectionResultsByKind.classById[constraint.foreignClassId]
182182
: introspectionResultsByKind.classById[constraint.classId];

src/PostgraphileNestedUpdatersPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function PostGraphileNestedUpdatersPlugin(builder) {
88
const { constraint } = options;
99
return this.camelCase(
1010
`update_by_${constraint.keyAttributes
11-
.map((k) => k.name)
11+
.map((k) => this.column(k))
1212
.join('_and_')}`,
1313
);
1414
},

0 commit comments

Comments
 (0)