Fork me on GitHub
#datomic
<
2019-05-29
>
Ben Hammond16:05:47

hi guys. I'm trying datomic cloud for the first time. I have used datomic on prem for several years. I am transacting a schema that I developed against an 'on prem' database and I get this error

Execution error (ExceptionInfo) at datomic.client.api.async/ares (async.clj:56).
Unable to resolve entity: :db/index

Ben Hammond16:05:33

I know there was regret about the :db/index true attribute in datomic schema

Ben Hammond16:05:49

has this been eliminated in datomic cloud?

Ben Hammond16:05:56

I definitely do want this attribute to be in AVET

ghadi16:05:57

like :db/index

Ben Hammond16:05:57

does that page describe the differences?

ghadi16:05:06

no that's the ref for cloud

Ben Hammond16:05:33

oh there's no [:db.fn/cas neither 8(

Ben Hammond16:05:57

Caused by: clojure.lang.ExceptionInfo: Unable to resolve data function: :db.fn/cas
	at datomic.client.api.async$ares.invokeStatic(async.clj:56)
	at datomic.client.api.async$ares.invoke(async.clj:52)
	at datomic.client.api.sync$eval18317$fn__18322.invoke(sync.clj:83)
	at datomic.client.api.protocols$eval16202$fn__16238$G__16187__16245.invoke(protocols.clj:58)
	at datomic.client.api$transact.invokeStatic(api.clj:172)
	at datomic.client.api$transact.invoke(api.clj:155)

Joe Lane16:05:07

Its under a different key, which may be the point you’re making.

favila16:05:07

renamed to :db/cas

Joe Lane16:05:24

Beat me to it 🙂

favila16:05:30

:db/index doesn't exist because all attrs are indexed by default now

👍 4
favila16:05:43

IOW it's always :db/index true

Ben Hammond16:05:46

that was what I hoped

Ben Hammond16:05:21

is there a specific doc describing the differences between cloud and on-prem?

Ben Hammond16:05:36

everyone must have gone through these pain points once

Joe Lane16:05:21

Eh, actually thats probably not helpful for you.

Ben Hammond16:05:29

ah doesn't quite cover these details though

Ben Hammond16:05:41

I don't feel so bad about asking then

hadils16:05:55

Can I use lacinia-pedestal with HTTP Direct? I keep getting a 500 error when it worked fine as a Lambda function…

Joe Lane16:05:43

@hadilsabbagh18 Can you show the handler function and the ion-config?

Joe Lane16:05:16

Lets start a thread

hadils16:05:54

Sure.

{:allow    [
            ;; transaction functions
            stackz.db/inc-attr
            stackz.db/xact-coll

            ;; query functions

            ;; lambda handlers
            stackz.schema/build-database

            ;; web applications
            stackz.dwolla/web-handler
            stackz.plaid/web-handler]


 :lambdas  {:build-database
            {:fn          stackz.schema/build-database
             :description "Builds the database if not already installed."}
            :dwolla
            {:fn          stackz.dwolla/web-handler
             :integration :api-gateway/proxy
             :description "Handles POST webhook calls from Dwolla"}
            :plaid
            {:fn          stackz.plaid/web-handler
             :integration :api-gateway/proxy
             :description "Handles POST webhook calls from Plaid"}}

 :http-direct {:handler-fn stackz.graphql/web-handler}

 :app-name "stackz-dev"}
(defn sm
  [interceptors schema graphiql?]
  (lacinia/service-map schema {:graphiql graphiql? :interceptors interceptors}))

(def service
  (-> (load-schema)
      (lacinia/default-interceptors {:graphiql false})
      (lacinia/inject jwt-interceptor :replace ::lacinia/inject-app-context)
      (sm (load-schema) false)
      (assoc ::http/chain-provider provider/ion-provider
             ::http/resource-path "/public"
             ::http/allowed-origins {:creds true})))

(defn handler
  "Ion handler"
  [service-map]
  (-> service-map
      cast-log
      http/default-interceptors
      http/create-provider
      cast-log))

(defn web-handler
  [request]
  (handler service) request)

hadils16:05:14

Oops sorry.

Joe Lane16:05:08

Well it looks like your web-handler is just returning the request object

souenzzo16:05:06

@hadilsabbagh18 try to print/log (get ctx :headers) before the last leave Could be related with it: https://github.com/pedestal/pedestal.ions/issues/3

hadils16:05:10

Do I do (apply (handler service) [request]?

Joe Lane16:05:30

@hadilsabbagh18 Can I see your original ionized version?

hadils16:05:29

Sure.

(def web-handler
  (handler service))

Joe Lane17:05:42

So you never called apigw/ionize?

hadils17:05:13

Oh sorry, just a minute.

hadils17:05:53

(def web-handler
  (apigw/ionize (handler service)))

hadils17:05:14

Do I still call ionize? Seem like I have to…

Joe Lane17:05:47

not for direct

Joe Lane17:05:00

Looking at the second link, it has the ion-config from the ion-starter repo. That references items-by-type directly, NOT items-by-type-ionized.

Joe Lane17:05:29

So in your case I think you would want (def web-handler (handler service))

hadils17:05:31

That didn't work when I tried it, because it takes the request argument explicitly (as a defn).

Joe Lane17:05:04

Didn’t work locally or didn’t work when deployed?

hadils17:05:11

When deployed.

hadils17:05:05

When I did the apply it gave a result that the body was an InputStream, not a String. That's progress…

hadils17:05:00

I think I need to an interceptor to expand the body…

Joe Lane17:05:49

I think you should try to deploy it right now, regardless of what it says locally with apply, and see what the results are. This is on a production topology correct? http-direct is only on a production topology, not a solo topology.

hadils17:05:55

I did. Here's the results:

{"message":"Invalid request: java.io.BufferedInputStream cannot be cast to java.lang.String"}

marshall17:05:57

You have to read the input stream

marshall17:05:11

As done on line 144

hadils17:05:30

@marshall You're correct. I need to add an interceptor to read the body.

hadils17:05:58

@joe.lane @marshall I believe that I don't need the Ion provider anymore, but I don't know how to disable Jetty from being used here. The Ion provider is expecting data from an ionized request, not the raw request from API Gateway.

hadils18:05:56

I think the solution is to use Pedestal’s ‘direct-apigw-provider’

henrik18:05:08

For input-streams, a simple slurp is usually enough.

hadils21:05:58

True @henrik, but I am trying to use Pedestal and want a provider that works with API Gateway.

kenny22:05:39

How would I migrate the data from an existing Datomic Cloud system to a new Datomic Cloud system?