Fork me on GitHub
#pathom
<
2023-11-16
>
Tyler Nisonoff17:11:18

Been working with the pathom3 graphql integration In the demo examples, I see authorization tokens being used in the github example, but the token is an env variable constant for any request. In my example, I have a pathom plugin authenticating the user from a JWT, and I want to pass this user-specific account information to my backend graphql instance, ideally via headers. However, p.gql/connect-graphql 's request fn only takes in the query, not the environment, so I'm having trouble figuring out how to pass this information along. Would a PR be accepted that allows for the environment to be passed into this fn as well? or is there a better way to accomplish this?

Tyler Nisonoff18:11:13

essentially something that looks like:

(defn auth-header-map [env]
  (if-let [acct-info (lib.auth/get-account-info env)]
    acct-info
    {}))

(defn request-vb-graphql
  "helper fn required by p.gql/connect-graphql to make graphql requests"
  [env query]
  #?(:clj
     (let [{:keys [host port]} (:config config)]
       (-> @(http/request
             {:url     (str "http://" host ":" (str port) "/graphql")
              :method  :post
              :headers (merge {"Content-Type" "application/json"
                               "Accept"       "*/*"}
                              (auth-header-map env))
              :body    (json/write-str {:query query})})
           :body
           json/read-str))))

wilkerlucio12:11:39

hello @U016TR1B18E, yeah, I think we will need to add also the environment, happy to discuss the change on a PR

Tyler Nisonoff21:11:41

Sounds good! gonna Open a PR with a breaking change here, but happy to discuss non-breaking alternatives and make the proper changes -- figured this'll just be a good starting point https://github.com/wilkerlucio/pathom3-graphql/pull/17

Tyler Nisonoff21:01:49

Hey Wilker, was wondering if you're still interested in the above PR? No real urgency on my part, just wanted to check in case it slipped your mind. Let me know if/how i can help get it over the finish line!

wilkerlucio14:01:10

hello Tyler, sorry, all the end of year things made me lose track of this, I'll have a look later today 😉

Tyler Nisonoff17:01:20

no problem at all!

wilkerlucio01:01:52

merged, thanks!

❤️ 1
Tyler Nisonoff22:01:57

@U066U8JQJ would you be up for cutting a new release of https://github.com/wilkerlucio/pathom3-graphql given this is merged?

wilkerlucio15:02:28

hey @U016TR1B18E, sorry the delay. I actually tried to do this the other day, but there are some new requirements on clojars that I have to fix to make a new release, I'll let you know once I get to it

Tyler Nisonoff15:02:42

All good appreciate it!