fix: Add a hint and clarification to the no relationship found error (#1858)

This commit is contained in:
laurenceisla
2021-05-31 12:15:31 -05:00
committed by GitHub
parent 88a481da8a
commit 1b12b112a1
3 changed files with 15 additions and 6 deletions
+2 -1
View File
@@ -86,7 +86,8 @@ instance JSON.ToJSON ApiRequestError where
toJSON InvalidRange = JSON.object [
"message" .= ("HTTP Range error" :: Text)]
toJSON (NoRelBetween parent child) = JSON.object [
"message" .= ("Could not find foreign keys between these entities. No relationship found between " <> parent <> " and " <> child :: Text)]
"hint" .= ("If a new foreign key between these entities was created in the database, try reloading the schema cache." :: Text),
"message" .= ("Could not find a relationship between " <> parent <> " and " <> child <> " in the schema cache" :: Text)]
toJSON (AmbiguousRelBetween parent child rels) = JSON.object [
"hint" .= ("By following the 'details' key, disambiguate the request by changing the url to /origin?select=relationship(*) or /origin?select=target!relationship(*)" :: Text),
"message" .= ("More than one relationship was found for " <> parent <> " and " <> child :: Text),
+9 -3
View File
@@ -184,7 +184,9 @@ spec =
it "fails if the fk is not known" $
get "/message?select=id,sender:person!space(name)&id=lt.4" `shouldRespondWith`
[json|{"message":"Could not find foreign keys between these entities. No relationship found between message and person"}|]
[json|{
"hint":"If a new foreign key between these entities was created in the database, try reloading the schema cache.",
"message":"Could not find a relationship between message and person in the schema cache"}|]
{ matchStatus = 400
, matchHeaders = [matchContentTypeJson] }
@@ -443,13 +445,17 @@ spec =
{ matchHeaders = [matchContentTypeJson] }
it "doesn't work if the junction is only internal" $
get "/end_1?select=end_2(*)" `shouldRespondWith`
[json|{"message":"Could not find foreign keys between these entities. No relationship found between end_1 and end_2"}|]
[json|{
"hint":"If a new foreign key between these entities was created in the database, try reloading the schema cache.",
"message":"Could not find a relationship between end_1 and end_2 in the schema cache"}|]
{ matchStatus = 400
, matchHeaders = [matchContentTypeJson] }
it "shouldn't try to embed if the private junction has an exposed homonym" $
-- ensures the "invalid reference to FROM-clause entry for table "rollen" error doesn't happen.
-- Ref: https://github.com/PostgREST/postgrest/issues/1587#issuecomment-734995669
get "/schauspieler?select=filme(*)" `shouldRespondWith`
[json|{"message":"Could not find foreign keys between these entities. No relationship found between schauspieler and filme"}|]
[json|{
"hint":"If a new foreign key between these entities was created in the database, try reloading the schema cache.",
"message":"Could not find a relationship between schauspieler and filme in the schema cache"}|]
{ matchStatus = 400
, matchHeaders = [matchContentTypeJson] }
+4 -2
View File
@@ -225,8 +225,10 @@ spec actualPgVersion = do
get "/items?always_false=is.false" `shouldRespondWith` 400
it "matches filtering nested items 2" $
get "/clients?select=id,projects(id,tasks2(id,name))&projects.tasks.name=like.Design*"
`shouldRespondWith` [json| {"message":"Could not find foreign keys between these entities. No relationship found between projects and tasks2"}|]
get "/clients?select=id,projects(id,tasks2(id,name))&projects.tasks.name=like.Design*" `shouldRespondWith`
[json| {
"hint":"If a new foreign key between these entities was created in the database, try reloading the schema cache.",
"message":"Could not find a relationship between projects and tasks2 in the schema cache"}|]
{ matchStatus = 400
, matchHeaders = [matchContentTypeJson]
}