Skip to content

Commit da3b15c

Browse files
authored
fix: one-to-many with multiple foreign keys to the same table (#107)
1 parent 26a4eb1 commit da3b15c

17 files changed

+1705
-27
lines changed

__tests__/fixtures/queries/relations.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ query {
2323
children_none_name_startsWith_c_and_childrenExist_false: allFilterables(filter: {childrenByFilterableId: {none: {name: {startsWith: "c"}}}, childrenByFilterableIdExist: false}) { ...childrenConnection }
2424
childrenExist_false: allFilterables(filter: {childrenByFilterableIdExist: false}) { ...childrenConnection }
2525
childrenExist_true: allFilterables(filter: {childrenByFilterableIdExist: true}) { ...childrenConnection }
26+
filterableClosuresByDescendantId_some_filterableByAncestorId_name_equalTo_Test: allFilterables(filter: { filterableClosuresByDescendantId: { some: { filterableByAncestorId: { name: { equalTo: "Test" } } } } }) { ...textConnection }
2627
forwardCompound_name_equalTo_forwardCompound12: allFilterables(filter: {forwardCompoundByForwardCompound1AndForwardCompound2: {name: {equalTo: "forwardCompound12"}}}) { ...textConnection }
2728
forwardCompoundExists_false: allFilterables(filter: {forwardCompoundByForwardCompound1AndForwardCompound2Exists: false}) { ...textConnection }
2829
forwardCompoundExists_true: allFilterables(filter: {forwardCompoundByForwardCompound1AndForwardCompound2Exists: true}) { ...textConnection }

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7096,6 +7096,18 @@ Object {
70967096
},
70977097
],
70987098
},
7099+
"filterableClosuresByDescendantId_some_filterableByAncestorId_name_equalTo_Test": Object {
7100+
"nodes": Array [
7101+
Object {
7102+
"id": 2,
7103+
"text": "Test",
7104+
},
7105+
Object {
7106+
"id": 3,
7107+
"text": "tEST",
7108+
},
7109+
],
7110+
},
70997111
"forwardCompoundExists_false": Object {
71007112
"nodes": Array [
71017113
Object {

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

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,64 @@ type Filterable implements Node {
20622062
): FilterableComputedSetofIntConnection!
20632063
computedTaggedFilterable: Int
20642064
date: Date
2065+
2066+
\\"\\"\\"Reads and enables pagination through a set of \`FilterableClosure\`.\\"\\"\\"
2067+
filterableClosuresByAncestorId(
2068+
\\"\\"\\"Read all values in the set after (below) this cursor.\\"\\"\\"
2069+
after: Cursor
2070+
2071+
\\"\\"\\"Read all values in the set before (above) this cursor.\\"\\"\\"
2072+
before: Cursor
2073+
2074+
\\"\\"\\"
2075+
A filter to be used in determining which values should be returned by the collection.
2076+
\\"\\"\\"
2077+
filter: FilterableClosureFilter
2078+
2079+
\\"\\"\\"Only read the first \`n\` values of the set.\\"\\"\\"
2080+
first: Int
2081+
2082+
\\"\\"\\"Only read the last \`n\` values of the set.\\"\\"\\"
2083+
last: Int
2084+
2085+
\\"\\"\\"
2086+
Skip the first \`n\` values from our \`after\` cursor, an alternative to cursor
2087+
based pagination. May not be used with \`last\`.
2088+
\\"\\"\\"
2089+
offset: Int
2090+
2091+
\\"\\"\\"The method to use when ordering \`FilterableClosure\`.\\"\\"\\"
2092+
orderBy: [FilterableClosuresOrderBy!] = [PRIMARY_KEY_ASC]
2093+
): FilterableClosuresConnection!
2094+
2095+
\\"\\"\\"Reads and enables pagination through a set of \`FilterableClosure\`.\\"\\"\\"
2096+
filterableClosuresByDescendantId(
2097+
\\"\\"\\"Read all values in the set after (below) this cursor.\\"\\"\\"
2098+
after: Cursor
2099+
2100+
\\"\\"\\"Read all values in the set before (above) this cursor.\\"\\"\\"
2101+
before: Cursor
2102+
2103+
\\"\\"\\"
2104+
A filter to be used in determining which values should be returned by the collection.
2105+
\\"\\"\\"
2106+
filter: FilterableClosureFilter
2107+
2108+
\\"\\"\\"Only read the first \`n\` values of the set.\\"\\"\\"
2109+
first: Int
2110+
2111+
\\"\\"\\"Only read the last \`n\` values of the set.\\"\\"\\"
2112+
last: Int
2113+
2114+
\\"\\"\\"
2115+
Skip the first \`n\` values from our \`after\` cursor, an alternative to cursor
2116+
based pagination. May not be used with \`last\`.
2117+
\\"\\"\\"
2118+
offset: Int
2119+
2120+
\\"\\"\\"The method to use when ordering \`FilterableClosure\`.\\"\\"\\"
2121+
orderBy: [FilterableClosuresOrderBy!] = [PRIMARY_KEY_ASC]
2122+
): FilterableClosuresConnection!
20652123
float4: Float
20662124
float8: Float
20672125
@@ -2110,6 +2168,97 @@ type Filterable implements Node {
21102168
xml: String
21112169
}
21122170
2171+
type FilterableClosure implements Node {
2172+
ancestorId: Int!
2173+
depth: Int!
2174+
descendantId: Int!
2175+
2176+
\\"\\"\\"
2177+
Reads a single \`Filterable\` that is related to this \`FilterableClosure\`.
2178+
\\"\\"\\"
2179+
filterableByAncestorId: Filterable
2180+
2181+
\\"\\"\\"
2182+
Reads a single \`Filterable\` that is related to this \`FilterableClosure\`.
2183+
\\"\\"\\"
2184+
filterableByDescendantId: Filterable
2185+
id: Int!
2186+
2187+
\\"\\"\\"
2188+
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
2189+
\\"\\"\\"
2190+
nodeId: ID!
2191+
}
2192+
2193+
\\"\\"\\"
2194+
A filter to be used against \`FilterableClosure\` object types. All fields are combined with a logical ‘and.’
2195+
\\"\\"\\"
2196+
input FilterableClosureFilter {
2197+
\\"\\"\\"Filter by the object’s \`ancestorId\` field.\\"\\"\\"
2198+
ancestorId: IntFilter
2199+
2200+
\\"\\"\\"Checks for all expressions in this list.\\"\\"\\"
2201+
and: [FilterableClosureFilter!]
2202+
2203+
\\"\\"\\"Filter by the object’s \`depth\` field.\\"\\"\\"
2204+
depth: IntFilter
2205+
2206+
\\"\\"\\"Filter by the object’s \`descendantId\` field.\\"\\"\\"
2207+
descendantId: IntFilter
2208+
2209+
\\"\\"\\"Filter by the object’s \`id\` field.\\"\\"\\"
2210+
id: IntFilter
2211+
2212+
\\"\\"\\"Negates the expression.\\"\\"\\"
2213+
not: FilterableClosureFilter
2214+
2215+
\\"\\"\\"Checks for any expressions in this list.\\"\\"\\"
2216+
or: [FilterableClosureFilter!]
2217+
}
2218+
2219+
\\"\\"\\"A connection to a list of \`FilterableClosure\` values.\\"\\"\\"
2220+
type FilterableClosuresConnection {
2221+
\\"\\"\\"
2222+
A list of edges which contains the \`FilterableClosure\` and cursor to aid in pagination.
2223+
\\"\\"\\"
2224+
edges: [FilterableClosuresEdge!]!
2225+
2226+
\\"\\"\\"A list of \`FilterableClosure\` objects.\\"\\"\\"
2227+
nodes: [FilterableClosure]!
2228+
2229+
\\"\\"\\"Information to aid in pagination.\\"\\"\\"
2230+
pageInfo: PageInfo!
2231+
2232+
\\"\\"\\"
2233+
The count of *all* \`FilterableClosure\` you could get from the connection.
2234+
\\"\\"\\"
2235+
totalCount: Int
2236+
}
2237+
2238+
\\"\\"\\"A \`FilterableClosure\` edge in the connection.\\"\\"\\"
2239+
type FilterableClosuresEdge {
2240+
\\"\\"\\"A cursor for use in pagination.\\"\\"\\"
2241+
cursor: Cursor
2242+
2243+
\\"\\"\\"The \`FilterableClosure\` at the end of the edge.\\"\\"\\"
2244+
node: FilterableClosure
2245+
}
2246+
2247+
\\"\\"\\"Methods to use when ordering \`FilterableClosure\`.\\"\\"\\"
2248+
enum FilterableClosuresOrderBy {
2249+
ANCESTOR_ID_ASC
2250+
ANCESTOR_ID_DESC
2251+
DEPTH_ASC
2252+
DEPTH_DESC
2253+
DESCENDANT_ID_ASC
2254+
DESCENDANT_ID_DESC
2255+
ID_ASC
2256+
ID_DESC
2257+
NATURAL
2258+
PRIMARY_KEY_ASC
2259+
PRIMARY_KEY_DESC
2260+
}
2261+
21132262
\\"\\"\\"A connection to a list of \`Int\` values.\\"\\"\\"
21142263
type FilterableComputedSetofIntConnection {
21152264
\\"\\"\\"
@@ -4550,6 +4699,15 @@ type Query implements Node {
45504699
filterableByForwardId(forwardId: Int!): Filterable
45514700
filterableById(id: Int!): Filterable
45524701
4702+
\\"\\"\\"Reads a single \`FilterableClosure\` using its globally unique \`ID\`.\\"\\"\\"
4703+
filterableClosure(
4704+
\\"\\"\\"
4705+
The globally unique \`ID\` to be used in selecting a single \`FilterableClosure\`.
4706+
\\"\\"\\"
4707+
nodeId: ID!
4708+
): FilterableClosure
4709+
filterableClosureById(id: Int!): FilterableClosure
4710+
45534711
\\"\\"\\"Reads a single \`Forward\` using its globally unique \`ID\`.\\"\\"\\"
45544712
forward(
45554713
\\"\\"\\"The globally unique \`ID\` to be used in selecting a single \`Forward\`.\\"\\"\\"

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

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,64 @@ type Filterable implements Node {
820820
): FilterableComputedSetofIntConnection!
821821
computedTaggedFilterable: Int
822822
date: Date
823+
824+
\\"\\"\\"Reads and enables pagination through a set of \`FilterableClosure\`.\\"\\"\\"
825+
filterableClosuresByAncestorId(
826+
\\"\\"\\"Read all values in the set after (below) this cursor.\\"\\"\\"
827+
after: Cursor
828+
829+
\\"\\"\\"Read all values in the set before (above) this cursor.\\"\\"\\"
830+
before: Cursor
831+
832+
\\"\\"\\"
833+
A filter to be used in determining which values should be returned by the collection.
834+
\\"\\"\\"
835+
filter: FilterableClosureFilter
836+
837+
\\"\\"\\"Only read the first \`n\` values of the set.\\"\\"\\"
838+
first: Int
839+
840+
\\"\\"\\"Only read the last \`n\` values of the set.\\"\\"\\"
841+
last: Int
842+
843+
\\"\\"\\"
844+
Skip the first \`n\` values from our \`after\` cursor, an alternative to cursor
845+
based pagination. May not be used with \`last\`.
846+
\\"\\"\\"
847+
offset: Int
848+
849+
\\"\\"\\"The method to use when ordering \`FilterableClosure\`.\\"\\"\\"
850+
orderBy: [FilterableClosuresOrderBy!] = [PRIMARY_KEY_ASC]
851+
): FilterableClosuresConnection!
852+
853+
\\"\\"\\"Reads and enables pagination through a set of \`FilterableClosure\`.\\"\\"\\"
854+
filterableClosuresByDescendantId(
855+
\\"\\"\\"Read all values in the set after (below) this cursor.\\"\\"\\"
856+
after: Cursor
857+
858+
\\"\\"\\"Read all values in the set before (above) this cursor.\\"\\"\\"
859+
before: Cursor
860+
861+
\\"\\"\\"
862+
A filter to be used in determining which values should be returned by the collection.
863+
\\"\\"\\"
864+
filter: FilterableClosureFilter
865+
866+
\\"\\"\\"Only read the first \`n\` values of the set.\\"\\"\\"
867+
first: Int
868+
869+
\\"\\"\\"Only read the last \`n\` values of the set.\\"\\"\\"
870+
last: Int
871+
872+
\\"\\"\\"
873+
Skip the first \`n\` values from our \`after\` cursor, an alternative to cursor
874+
based pagination. May not be used with \`last\`.
875+
\\"\\"\\"
876+
offset: Int
877+
878+
\\"\\"\\"The method to use when ordering \`FilterableClosure\`.\\"\\"\\"
879+
orderBy: [FilterableClosuresOrderBy!] = [PRIMARY_KEY_ASC]
880+
): FilterableClosuresConnection!
823881
float4: Float
824882
float8: Float
825883
@@ -868,6 +926,97 @@ type Filterable implements Node {
868926
xml: String
869927
}
870928
929+
type FilterableClosure implements Node {
930+
ancestorId: Int!
931+
depth: Int!
932+
descendantId: Int!
933+
934+
\\"\\"\\"
935+
Reads a single \`Filterable\` that is related to this \`FilterableClosure\`.
936+
\\"\\"\\"
937+
filterableByAncestorId: Filterable
938+
939+
\\"\\"\\"
940+
Reads a single \`Filterable\` that is related to this \`FilterableClosure\`.
941+
\\"\\"\\"
942+
filterableByDescendantId: Filterable
943+
id: Int!
944+
945+
\\"\\"\\"
946+
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
947+
\\"\\"\\"
948+
nodeId: ID!
949+
}
950+
951+
\\"\\"\\"
952+
A filter to be used against \`FilterableClosure\` object types. All fields are combined with a logical ‘and.’
953+
\\"\\"\\"
954+
input FilterableClosureFilter {
955+
\\"\\"\\"Filter by the object’s \`ancestorId\` field.\\"\\"\\"
956+
ancestorId: IntFilter
957+
958+
\\"\\"\\"Checks for all expressions in this list.\\"\\"\\"
959+
and: [FilterableClosureFilter!]
960+
961+
\\"\\"\\"Filter by the object’s \`depth\` field.\\"\\"\\"
962+
depth: IntFilter
963+
964+
\\"\\"\\"Filter by the object’s \`descendantId\` field.\\"\\"\\"
965+
descendantId: IntFilter
966+
967+
\\"\\"\\"Filter by the object’s \`id\` field.\\"\\"\\"
968+
id: IntFilter
969+
970+
\\"\\"\\"Negates the expression.\\"\\"\\"
971+
not: FilterableClosureFilter
972+
973+
\\"\\"\\"Checks for any expressions in this list.\\"\\"\\"
974+
or: [FilterableClosureFilter!]
975+
}
976+
977+
\\"\\"\\"A connection to a list of \`FilterableClosure\` values.\\"\\"\\"
978+
type FilterableClosuresConnection {
979+
\\"\\"\\"
980+
A list of edges which contains the \`FilterableClosure\` and cursor to aid in pagination.
981+
\\"\\"\\"
982+
edges: [FilterableClosuresEdge!]!
983+
984+
\\"\\"\\"A list of \`FilterableClosure\` objects.\\"\\"\\"
985+
nodes: [FilterableClosure]!
986+
987+
\\"\\"\\"Information to aid in pagination.\\"\\"\\"
988+
pageInfo: PageInfo!
989+
990+
\\"\\"\\"
991+
The count of *all* \`FilterableClosure\` you could get from the connection.
992+
\\"\\"\\"
993+
totalCount: Int
994+
}
995+
996+
\\"\\"\\"A \`FilterableClosure\` edge in the connection.\\"\\"\\"
997+
type FilterableClosuresEdge {
998+
\\"\\"\\"A cursor for use in pagination.\\"\\"\\"
999+
cursor: Cursor
1000+
1001+
\\"\\"\\"The \`FilterableClosure\` at the end of the edge.\\"\\"\\"
1002+
node: FilterableClosure
1003+
}
1004+
1005+
\\"\\"\\"Methods to use when ordering \`FilterableClosure\`.\\"\\"\\"
1006+
enum FilterableClosuresOrderBy {
1007+
ANCESTOR_ID_ASC
1008+
ANCESTOR_ID_DESC
1009+
DEPTH_ASC
1010+
DEPTH_DESC
1011+
DESCENDANT_ID_ASC
1012+
DESCENDANT_ID_DESC
1013+
ID_ASC
1014+
ID_DESC
1015+
NATURAL
1016+
PRIMARY_KEY_ASC
1017+
PRIMARY_KEY_DESC
1018+
}
1019+
8711020
\\"\\"\\"A connection to a list of \`Int\` values.\\"\\"\\"
8721021
type FilterableComputedSetofIntConnection {
8731022
\\"\\"\\"
@@ -2490,6 +2639,15 @@ type Query implements Node {
24902639
filterableByForwardId(forwardId: Int!): Filterable
24912640
filterableById(id: Int!): Filterable
24922641
2642+
\\"\\"\\"Reads a single \`FilterableClosure\` using its globally unique \`ID\`.\\"\\"\\"
2643+
filterableClosure(
2644+
\\"\\"\\"
2645+
The globally unique \`ID\` to be used in selecting a single \`FilterableClosure\`.
2646+
\\"\\"\\"
2647+
nodeId: ID!
2648+
): FilterableClosure
2649+
filterableClosureById(id: Int!): FilterableClosure
2650+
24932651
\\"\\"\\"Reads a single \`Forward\` using its globally unique \`ID\`.\\"\\"\\"
24942652
forward(
24952653
\\"\\"\\"The globally unique \`ID\` to be used in selecting a single \`Forward\`.\\"\\"\\"

0 commit comments

Comments
 (0)