runQuery :: (Monad m) => Schema m -> B.ByteString -> JSON.Value -> m Builder
runQuery s q v =  collect
              <$> either (\e -> return (byteString "null", [ BC8.pack e ]))
                         (execute s v)
                         (parseDocument q)
  where collect (res, []) = byteString "{\"data\":" <> res <> byteString "}"
        collect (res, es) = byteString "{\"data\":"
                         <> res
                         <> byteString ", \"errors\": "
                         <> joinList [ buildString e | e <- es ]
                         <> byteString "}"
runQuery :: (Monad m) => Schema m -> B.ByteString -> JSON.Value -> m Builder
runQuery s q v =  collect
              <$> either (\e -> return (byteString "null", [ BC8.pack e ]))
                         (execute s v)
                         (parseDocument q)
  where collect (res, []) = byteString "{\"data\":" <> res <> byteString "}"
        collect (res, es) = byteString "{\"data\":"
                         <> res
                         <> byteString ", \"errors\": "
                         <> joinList [ buildString e | e <- es ]
                         <> byteString "}"
runQuery s q v =  collect
              <$> either (\e -> return (byteString "null", [ BC8.pack e ]))
                         (execute s v)
                         (parseDocument q)
  where collect (res, []) = byteString "{\"data\":" <> res <> byteString "}"
        collect (res, es) = byteString "{\"data\":"
                         <> res
                         <> byteString ", \"errors\": "
                         <> joinList [ buildString e | e <- es ]
                         <> byteString "}"