-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find a way to add descriptions to queries and mutations #11
Comments
Would it be possible to access the docstrings of resolver functions for this? Fields could get their description from the |
That would definitely be ideal...if specs had docstrings :/ Right now I think we'll have to make do with expanding the attach fns so they can optionally accept a description. |
Alex said that docstrings are still on the list of things to be included in spec.alpha2. I personally would just wait for that, instead of adding a bandaid that then has to be maintained indefinitely. |
@acron0 I would like to work on this, if no one else already is. |
@Wryhder Yep, please do 👍 |
Hi, I hope I have understood what the issue is but what if the "docstrings" were pulled from the resolvers for example: (defmacro doc-string
[symbol]
`(:doc (meta (var ~symbol)))) Then this would be called by a function (defn attach-doc-string
[function]
(let [doc (doc-string function)]
(if doc
doc
"please add a description"))) I am not sure where to put this description yet, I went ahead and naively attached it to the (defn attach-query
"Adds a query resolver into the provided pre-compiled data structure"
#_([m resolver]
;; TODO infer specs from fdef
)
([m query-spec results-spec resolver]
{:pre [(s/valid? ::pre-compiled-data m)]}
(-> m
(update :specs conj results-spec)
(update :queries assoc results-spec {:resolver resolver
:query-spec query-spec
:description (util/attach-doc-string resolver)}))))
This strategy may help when the specs are later inferred. |
@kevinmungai Yes, this is basically 50% of the solution! The description then needs to be pushed into the schema as a kind of post-generation step. |
@acron0 Thanksl for the feedback. It will take me sometime before I get a working solution. |
Hi @acron0, I am having a bit of an issue. I have tried to generate a simple schema from the example on the README but I just can't. the expecteda lacinia schema should be generated using this (spec/def ::query-spec map?)
(spec/def ::response map?)
(-> (leona/create)
(leona/attach-query ::query-spec ::response (fn [context query value]))
(leona/compile)) what am experiencing
what I have tried
To be honest this is my first time trying to contribute to open source, I think I might be the issue but after 2 days of trying I have decided to ask for help. Thank you for your time. |
If you successfully complete this Issue via WorskHub there's a $75 reward available. |
@umitduran started working on this issue via WorksHub. |
@kevinmungai Don't worry :) Leona is still young, and there is still some holes in the documentation so that could be the problem here. What version of Leona are you using? And you say running the tests gives you a |
@tolgraven started working on this issue via WorksHub. |
and WorksHub#11 (description support), both working but in need of tests eetc and especially design decisions before any further work.
An user started working on this issue via WorksHub. |
@chandanlal92 started working on this issue via WorksHub. |
@ynohtna82nosredna started working on this issue via WorksHub. |
A user started working on this issue via WorksHub. |
Hi, @acron0 ! May I suggest using (s/def ::droid-query (st/spec {:spec (s/keys :req-un [::id]
:opt [::appears-in])
:description "Query for droid"}))
(-> (leona/create)
(leona/attach-query ::droid-query ::droid droid-resolver)
...) |
@wizzytod Yes, I would accept PR that connects the dots to make this work |
A user started working on this issue via WorksHub. |
@ansari691 started working on this issue via WorksHub. |
@benjamin-asdf started working on this issue via WorksHub. |
;; :leona/description metadata on a resolver or mutation
;; -> add description to the object
(let [job-resolver (fn [c q v])
job-resolver-with-meta
(with-meta job-resolver {:leona/description "foo"})
compiled-schema (-> (leona/create)
(leona/attach-query ::job-input :wh/job job-resolver-with-meta)
(leona/compile))]
(-> compiled-schema
:generated :objects :Job :description))
"foo"
;; Fields and args can also have descriptions, for completeness we would want a way to provide those?
;; not sure if metada conceptually makes sense, but we could add a :descriptions key to compile opts?
(leona/compile
m
{:descriptions {:wh/job "a job"
:wh.company/name {:fields "company name"
:args "company name arg"}
:wh.job/id {:fields "the id of a job"
:args "the id of a job"}}})
Update, thoughts: Instead of args to |
For documentation purposes, it would be nice if there was a way to add descriptions to queries and mutations so that they appear in GraphQL introspection.
For example, this could be achieved by including a description in the
attach-query
/attach-mutation
function call. A preferable way would either be with docstring or metadata on the handler.The text was updated successfully, but these errors were encountered: