debug-ito / greskell

Haskell binding for Gremlin graph query language
https://hackage.haskell.org/package/greskell
27 stars 4 forks source link

Getting started #2

Closed JeffreyBenjaminBrown closed 5 years ago

JeffreyBenjaminBrown commented 5 years ago

Thanks for this repo! I can't wait to dig in.

It took me a day of work to get Greskell working. I'm hoping that by sharing this recipe I can save others some time. The problem is mostly not in Greskell; it's that there are a gazillion ways to use Gremlin. Eventually I struck on the following, which works:

submitExample :: IO [Int] submitExample = bracket (connect "localhost" 8182) close $ \client -> do let (g, binding) = runBinder $ plusTen 50 result_handle <- submit client g (Just binding) fmap toList $ slurpResults result_handle

plusTen :: Int -> Binder (Greskell Int) plusTen x = do var_x <- newBind x return $ var_x + 10

main :: IO () main = hspec $ specify "submit" $ do egot <- try submitExample :: IO (Either SomeException [Int]) case egot of Left _ -> print "LEFT" >> return () -- probably there's no server running Right got -> print "RIGHT" >> (got shouldBe [60])


* From within the cloned repo, run `stack ghci`
* From within GHCI, run `:l test-server`, then run `main`.
* If it worked, it will print `RIGHT` to the screen. 
* If you stop the docker image that's running Gremlin Server, `main` should instead print `LEFT`.

If there's a more elegant solution, I'm all ears!
debug-ito commented 5 years ago

Thanks for reporting!

To run examples of README.md, just type stack test test-readme. You can directly modify README.md.

I'll revise the README.md to show that fact.

debug-ito commented 5 years ago

Updated README.md and "submit" example.