这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug fixes and improvements

- server: add support for `_inc` on `real`, `double`, `numeric` and `money` (fix #3573)
- server: support special characters in JSON path query argument with bracket `[]` notation, e.g `obj['Hello World!']` (#3890) (#4482)

## `v1.2.0-beta.4`

Expand Down Expand Up @@ -46,7 +47,7 @@ The order, collapsed state of columns and page size is now persisted across page
- server: `type` field is not required if `jwk_url` is provided in JWT config
- server: add a new field `claims_namespace_path` which accepts a JSON Path for looking up hasura claim in the JWT token (#4349)
- server: support reusing Postgres scalars in custom types (close #4125)

## `v1.2.0-beta.3`

### console: manage Postgres check constraints
Expand Down Expand Up @@ -163,5 +164,4 @@ Read more about it in the [docs](https://hasura.io/docs/1.0/graphql/manual/auth/

- server: check expression in update permissions (close #384) (rfc #3750) (#3804)
- console: show pre-release update notifications with opt out option (#3888)
- Allow special characters in JSON path query argument with bracket `[]` notation, e.g `obj['Hello World!']` (#3890)
- console: handle invalid keys in permission builder (close #3848) (#3863)
1 change: 1 addition & 0 deletions server/src-lib/Data/Parser/JSONPath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Data.Aeson.Internal (JSONPath, JSONPathElement (..))
import Data.Attoparsec.Text

parseJSONPath :: T.Text -> Either String JSONPath
parseJSONPath "$" = Right []
parseJSONPath txt = first (const invalidMessage) $
parseOnly (optional (char '$') *> many1' element <* endOfInput) txt
where
Expand Down
15 changes: 9 additions & 6 deletions server/src-lib/Hasura/GraphQL/Resolve/Select.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ import Hasura.RQL.Types
import Hasura.SQL.Types
import Hasura.SQL.Value

jsonPathToColExp :: (MonadError QErr m) => T.Text -> m S.SQLExp
jsonPathToColExp :: (MonadError QErr m) => T.Text -> m (Maybe S.SQLExp)
jsonPathToColExp t = case parseJSONPath t of
Left s -> throw400 ParseFailed $ T.pack $ "parse json path error: " ++ s
Right jPaths -> return $ S.SEArray $ map elToColExp jPaths
Right [] -> return Nothing
Right jPaths -> return $ Just $ S.SEArray $ map elToColExp jPaths
where
elToColExp (Key k) = S.SELit k
elToColExp (Index i) = S.SELit $ T.pack (show i)


argsToColOp :: (MonadReusability m, MonadError QErr m) => ArgsMap -> m (Maybe RS.ColOp)
argsToColOp args = maybe (return Nothing) toOp $ Map.lookup "path" args
where
toJsonPathExp = fmap (RS.ColOp S.jsonbPathOp) . jsonPathToColExp
toOp v = asPGColTextM v >>= traverse toJsonPathExp
argsToColOp args = case Map.lookup "path" args of
Nothing -> return Nothing
Just txt -> do
mColTxt <- asPGColTextM txt
mColExps <- maybe (return Nothing) jsonPathToColExp mColTxt
return $ RS.ColOp S.jsonbPathOp <$> mColExps

type AnnFlds = RS.AnnFldsG UnresolvedVal

Expand Down
22 changes: 14 additions & 8 deletions server/src-test/Data/Parser/JSONPathSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ spec = describe "encode and parse JSONPath" $ do
forM_ generateTestEncodeJSONPath $ \(jsonPath, result) ->
encodeJSONPath jsonPath `shouldBe` result

it "JSONPath parser" $
withMaxSuccess 1000 $
forAll(resize 20 generateJSONPath) $ \jsonPath ->
let encPath = encodeJSONPath jsonPath
parsedJSONPathE = parseJSONPath $ T.pack encPath
in case parsedJSONPathE of
Left err -> counterexample (err <> ": " <> encPath) False
Right parsedJSONPath -> property $ parsedJSONPath == jsonPath
describe "JSONPath parser" $ do

it "Single $" $
parseJSONPath "$" `shouldBe` (Right [] :: Either String JSONPath)

it "Random json paths" $
withMaxSuccess 1000 $
forAll (resize 20 generateJSONPath) $ \jsonPath ->
let encPath = encodeJSONPath jsonPath
parsedJSONPathE = parseJSONPath $ T.pack encPath
in case parsedJSONPathE of
Left err -> counterexample (err <> ": " <> encPath) False
Right parsedJSONPath -> property $ parsedJSONPath == jsonPath



generateTestEncodeJSONPath :: [(JSONPath, String)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ response:
hello world!: hi
objs:
- 你好: Hello!
c32_json_dollar:
a: b
obj:
c1: c2
arr: [1,2,3]
_underscore: 0
'!@#$%^': special
translations:
hello world!: hi
objs:
- 你好: Hello!
c32_json_child_prop: c2
c32_json_child_prop_no_dot: b
c32_json_array_item: 1
Expand All @@ -57,9 +68,20 @@ response:
c32_json_nested_special_array_double_quote_dot: Hello!
c33_jsonb:
c: d
arr: [4,5,6]
obj:
e1: e2
objs:
- 你好: Hello!
'!@#$%^': special
_underscore: 0
translations:
hello world!: hi
c33_jsonb_dollar:
c: d
arr: [4,5,6]
obj:
e1: e2
arr: [4,5,6]
e1: e2
objs:
- 你好: Hello!
'!@#$%^': special
Expand Down Expand Up @@ -130,6 +152,7 @@ query:
c30_inet
c31_macaddr
c32_json
c32_json_dollar: c32_json(path: "$")
c32_json_child_prop: c32_json(path: ".obj.c1")
c32_json_child_prop_no_dot: c32_json(path: "a")
c32_json_array_item: c32_json(path: "arr[0]")
Expand All @@ -140,6 +163,7 @@ query:
c32_json_nested_special_array_double_quote: c32_json(path: "objs[0][\"你好\"]")
c32_json_nested_special_array_double_quote_dot: c32_json(path: "objs[0].[\"你好\"]")
c33_jsonb
c33_jsonb_dollar: c33_jsonb(path: "$")
c33_jsonb_child_prop: c33_jsonb(path: ".obj.e1")
c33_jsonb_child_prop_no_dot: c33_jsonb(path: "c")
c33_jsonb_array_item: c33_jsonb(path: "arr[2]")
Expand Down