Skip to content

Commit 324f066

Browse files
committed
fix(utils): fix smart tags for attributes
1 parent 17c8637 commit 324f066

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

packages/graphile-utils/__tests__/__snapshots__/makePgSmartTagsPlugin.test.js.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ type TestSmartTag implements Node {
249249
"""
250250
nodeId: ID!
251251
email: String!
252-
value: Int
252+
val: Int
253253
254254
"""Reads a single \`User\` that is related to this \`TestSmartTag\`."""
255255
userByEmail: User
@@ -263,8 +263,8 @@ input TestSmartTagCondition {
263263
"""Checks for equality with the object’s \`email\` field."""
264264
email: String
265265
266-
"""Checks for equality with the object’s \`value\` field."""
267-
value: Int
266+
"""Checks for equality with the object’s \`val\` field."""
267+
val: Int
268268
}
269269
270270
"""A connection to a list of \`TestSmartTag\` values."""
@@ -298,8 +298,8 @@ enum TestSmartTagsOrderBy {
298298
NATURAL
299299
EMAIL_ASC
300300
EMAIL_DESC
301-
VALUE_ASC
302-
VALUE_DESC
301+
VAL_ASC
302+
VAL_DESC
303303
PRIMARY_KEY_ASC
304304
PRIMARY_KEY_DESC
305305
}

packages/graphile-utils/__tests__/makePgSmartTagsPlugin.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ it("allows adding a custom single field to PG schema", async () => {
3232
primaryKey: "email",
3333
foreignKey: "(email) references graphile_utils.users (email)",
3434
},
35+
attribute: {
36+
value: {
37+
tags: {
38+
name: "val",
39+
},
40+
},
41+
},
3542
},
3643
},
3744
},
@@ -50,7 +57,7 @@ it("allows adding a custom single field to PG schema", async () => {
5057
email
5158
testSmartTagByEmail {
5259
email
53-
value
60+
val
5461
}
5562
}
5663
}
@@ -74,14 +81,14 @@ it("allows adding a custom single field to PG schema", async () => {
7481
"email": "bob@example.com",
7582
"testSmartTagByEmail": Object {
7683
"email": "bob@example.com",
77-
"value": 42,
84+
"val": 42,
7885
},
7986
},
8087
Object {
8188
"email": "caroline@example.com",
8289
"testSmartTagByEmail": Object {
8390
"email": "caroline@example.com",
84-
"value": 9999,
91+
"val": 9999,
8592
},
8693
},
8794
],

packages/graphile-utils/src/makePgSmartTagsPlugin.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,24 @@ export function makePgSmartTagsPlugin(
134134
pgIntrospectionResultsByKind
135135
);
136136
}
137+
138+
/**
139+
* The introspection results aren't currently on Build (we're helping
140+
* this happen now!), so we're going to fake it to make the API more
141+
* straightforward
142+
*/
143+
const buildWithIntrospection = {
144+
...build,
145+
pgIntrospectionResultsByKind,
146+
};
147+
137148
rules.forEach((rule, idx) => {
138149
const relevantIntrospectionResults: PgEntity[] =
139150
pgIntrospectionResultsByKind[rule.kind];
140151

141152
let hits = 0;
142153
relevantIntrospectionResults.forEach(entity => {
143-
if (!rule.match(entity, build)) {
154+
if (!rule.match(entity, buildWithIntrospection)) {
144155
return;
145156
}
146157
hits++;

0 commit comments

Comments
 (0)