Skip to content

Commit 326d149

Browse files
authored
fix(dynamicJson): fix handling of JSON array input (#93)
1 parent c6b3bb1 commit 326d149

18 files changed

+1230
-58
lines changed

__tests__/fixtures/queries/dynamicJson.graphql

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
query dynamicJsonFalse(
2+
$withArrayV2: JSON = "[{\"key2\":2},{\"key3\":3}]"
3+
$withObjectV2: JSON = "{\"key2\":2}"
4+
) {
5+
withArray: allJsonbTests(
6+
filter: { jsonbWithArray: { equalTo: $withArrayV2 } }
7+
) {
8+
...nodes
9+
}
10+
withObject: allJsonbTests(
11+
filter: { jsonbWithObject: { equalTo: $withObjectV2 } }
12+
) {
13+
...nodes
14+
}
15+
}
16+
17+
fragment nodes on JsonbTestsConnection {
18+
nodes {
19+
id
20+
}
21+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
query dynamicJsonTrue(
2+
$varInt: Int = 2
3+
$varJSON: JSON = { key2: 2 }
4+
$varJSONFilter: JSONFilter = { contains: { key2: 2 } }
5+
$withArrayV2: JSON = [{ key2: 2 }, { key3: 3 }]
6+
$withObjectV2: JSON = { key2: 2 }
7+
) {
8+
# The first four (a, b, c, d) should result in the same value
9+
a: allJsonbTests(filter: { jsonbWithObject: { contains: { key2: 2 } } }) {
10+
...nodes
11+
}
12+
b: allJsonbTests(
13+
filter: { jsonbWithObject: { contains: { key2: $varInt } } }
14+
) {
15+
...nodes
16+
}
17+
c: allJsonbTests(filter: { jsonbWithObject: { contains: $varJSON } }) {
18+
...nodes
19+
}
20+
d: allJsonbTests(filter: { jsonbWithObject: $varJSONFilter }) {
21+
...nodes
22+
}
23+
withArray: allJsonbTests(
24+
filter: { jsonbWithArray: { equalTo: $withArrayV2 } }
25+
) {
26+
...nodes
27+
}
28+
withObject: allJsonbTests(
29+
filter: { jsonbWithObject: { equalTo: $withObjectV2 } }
30+
) {
31+
...nodes
32+
}
33+
}
34+
35+
fragment nodes on JsonbTestsConnection {
36+
nodes {
37+
id
38+
}
39+
}

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4939,7 +4939,28 @@ Object {
49394939
}
49404940
`;
49414941

4942-
exports[`dynamicJson.graphql 1`] = `
4942+
exports[`dynamicJsonFalse.graphql 1`] = `
4943+
Object {
4944+
"data": Object {
4945+
"withArray": Object {
4946+
"nodes": Array [
4947+
Object {
4948+
"id": 2,
4949+
},
4950+
],
4951+
},
4952+
"withObject": Object {
4953+
"nodes": Array [
4954+
Object {
4955+
"id": 2,
4956+
},
4957+
],
4958+
},
4959+
},
4960+
}
4961+
`;
4962+
4963+
exports[`dynamicJsonTrue.graphql 1`] = `
49434964
Object {
49444965
"data": Object {
49454966
"a": Object {
@@ -4970,6 +4991,20 @@ Object {
49704991
},
49714992
],
49724993
},
4994+
"withArray": Object {
4995+
"nodes": Array [
4996+
Object {
4997+
"id": 2,
4998+
},
4999+
],
5000+
},
5001+
"withObject": Object {
5002+
"nodes": Array [
5003+
Object {
5004+
"id": 2,
5005+
},
5006+
],
5007+
},
49735008
},
49745009
}
49755010
`;

__tests__/integration/queries.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ beforeAll(() => {
9898
// some specific fixtures against a schema configured slightly
9999
// differently.
100100
const schemas = {
101-
"dynamicJson.graphql": gqlSchemas.dynamicJson,
101+
"dynamicJsonTrue.graphql": gqlSchemas.dynamicJson,
102102
"relations.graphql": gqlSchemas.relations,
103103
"simpleCollections.graphql": gqlSchemas.simpleCollections,
104104
"nullAndEmptyAllowed.graphql": gqlSchemas.nullAndEmptyAllowed,

__tests__/integration/schema/__snapshots__/allowedFieldTypes.test.js.snap

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,73 @@ A JavaScript object encoded in the JSON format as specified by [ECMA-404](http:/
15371537
\\"\\"\\"
15381538
scalar JSON
15391539
1540+
type JsonbTest implements Node {
1541+
id: Int!
1542+
jsonbWithArray: JSON
1543+
jsonbWithObject: JSON
1544+
1545+
\\"\\"\\"
1546+
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
1547+
\\"\\"\\"
1548+
nodeId: ID!
1549+
}
1550+
1551+
\\"\\"\\"
1552+
A filter to be used against \`JsonbTest\` object types. All fields are combined with a logical ‘and.’
1553+
\\"\\"\\"
1554+
input JsonbTestFilter {
1555+
\\"\\"\\"Checks for all expressions in this list.\\"\\"\\"
1556+
and: [JsonbTestFilter!]
1557+
1558+
\\"\\"\\"Filter by the object’s \`id\` field.\\"\\"\\"
1559+
id: IntFilter
1560+
1561+
\\"\\"\\"Negates the expression.\\"\\"\\"
1562+
not: JsonbTestFilter
1563+
1564+
\\"\\"\\"Checks for any expressions in this list.\\"\\"\\"
1565+
or: [JsonbTestFilter!]
1566+
}
1567+
1568+
\\"\\"\\"A connection to a list of \`JsonbTest\` values.\\"\\"\\"
1569+
type JsonbTestsConnection {
1570+
\\"\\"\\"
1571+
A list of edges which contains the \`JsonbTest\` and cursor to aid in pagination.
1572+
\\"\\"\\"
1573+
edges: [JsonbTestsEdge!]!
1574+
1575+
\\"\\"\\"A list of \`JsonbTest\` objects.\\"\\"\\"
1576+
nodes: [JsonbTest]!
1577+
1578+
\\"\\"\\"Information to aid in pagination.\\"\\"\\"
1579+
pageInfo: PageInfo!
1580+
1581+
\\"\\"\\"The count of *all* \`JsonbTest\` you could get from the connection.\\"\\"\\"
1582+
totalCount: Int
1583+
}
1584+
1585+
\\"\\"\\"A \`JsonbTest\` edge in the connection.\\"\\"\\"
1586+
type JsonbTestsEdge {
1587+
\\"\\"\\"A cursor for use in pagination.\\"\\"\\"
1588+
cursor: Cursor
1589+
1590+
\\"\\"\\"The \`JsonbTest\` at the end of the edge.\\"\\"\\"
1591+
node: JsonbTest
1592+
}
1593+
1594+
\\"\\"\\"Methods to use when ordering \`JsonbTest\`.\\"\\"\\"
1595+
enum JsonbTestsOrderBy {
1596+
ID_ASC
1597+
ID_DESC
1598+
JSONB_WITH_ARRAY_ASC
1599+
JSONB_WITH_ARRAY_DESC
1600+
JSONB_WITH_OBJECT_ASC
1601+
JSONB_WITH_OBJECT_DESC
1602+
NATURAL
1603+
PRIMARY_KEY_ASC
1604+
PRIMARY_KEY_DESC
1605+
}
1606+
15401607
type Junction implements Node {
15411608
\\"\\"\\"
15421609
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
@@ -2054,6 +2121,35 @@ type Query implements Node {
20542121
orderBy: [FullyOmittedsOrderBy!] = [PRIMARY_KEY_ASC]
20552122
): FullyOmittedsConnection
20562123
2124+
\\"\\"\\"Reads and enables pagination through a set of \`JsonbTest\`.\\"\\"\\"
2125+
allJsonbTests(
2126+
\\"\\"\\"Read all values in the set after (below) this cursor.\\"\\"\\"
2127+
after: Cursor
2128+
2129+
\\"\\"\\"Read all values in the set before (above) this cursor.\\"\\"\\"
2130+
before: Cursor
2131+
2132+
\\"\\"\\"
2133+
A filter to be used in determining which values should be returned by the collection.
2134+
\\"\\"\\"
2135+
filter: JsonbTestFilter
2136+
2137+
\\"\\"\\"Only read the first \`n\` values of the set.\\"\\"\\"
2138+
first: Int
2139+
2140+
\\"\\"\\"Only read the last \`n\` values of the set.\\"\\"\\"
2141+
last: Int
2142+
2143+
\\"\\"\\"
2144+
Skip the first \`n\` values from our \`after\` cursor, an alternative to cursor
2145+
based pagination. May not be used with \`last\`.
2146+
\\"\\"\\"
2147+
offset: Int
2148+
2149+
\\"\\"\\"The method to use when ordering \`JsonbTest\`.\\"\\"\\"
2150+
orderBy: [JsonbTestsOrderBy!] = [PRIMARY_KEY_ASC]
2151+
): JsonbTestsConnection
2152+
20572153
\\"\\"\\"Reads and enables pagination through a set of \`Junction\`.\\"\\"\\"
20582154
allJunctions(
20592155
\\"\\"\\"Read all values in the set after (below) this cursor.\\"\\"\\"
@@ -2447,6 +2543,15 @@ type Query implements Node {
24472543
offset: Int
24482544
): FuncTaggedFilterableReturnsTableMultiColConnection!
24492545
2546+
\\"\\"\\"Reads a single \`JsonbTest\` using its globally unique \`ID\`.\\"\\"\\"
2547+
jsonbTest(
2548+
\\"\\"\\"
2549+
The globally unique \`ID\` to be used in selecting a single \`JsonbTest\`.
2550+
\\"\\"\\"
2551+
nodeId: ID!
2552+
): JsonbTest
2553+
jsonbTestById(id: Int!): JsonbTest
2554+
24502555
\\"\\"\\"Reads a single \`Junction\` using its globally unique \`ID\`.\\"\\"\\"
24512556
junction(
24522557
\\"\\"\\"The globally unique \`ID\` to be used in selecting a single \`Junction\`.\\"\\"\\"

0 commit comments

Comments
 (0)