Skip to content
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

Open
acron0 opened this issue Jan 24, 2019 · 24 comments
Open

Find a way to add descriptions to queries and mutations #11

acron0 opened this issue Jan 24, 2019 · 24 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@acron0
Copy link
Member

acron0 commented Jan 24, 2019

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.

@acron0 acron0 added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jan 24, 2019
@devurandom
Copy link

devurandom commented Mar 23, 2019

Would it be possible to access the docstrings of resolver functions for this? Fields could get their description from the s/def docstring: https://dev.clojure.org/jira/browse/CLJ-1965

@acron0
Copy link
Member Author

acron0 commented Mar 27, 2019

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.

@devurandom
Copy link

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.

@Wryhder
Copy link

Wryhder commented Aug 31, 2019

Right now I think we'll have to make do with expanding the attach fns so they can optionally accept a description.

@acron0 I would like to work on this, if no one else already is.

@acron0
Copy link
Member Author

acron0 commented Sep 2, 2019

@Wryhder Yep, please do 👍

@kevinmungai
Copy link

kevinmungai commented Sep 12, 2019

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 :result-spec. Some guidance would assist me on where to put it.

(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.

@acron0
Copy link
Member Author

acron0 commented Sep 13, 2019

@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.

@kevinmungai
Copy link

@acron0 Thanksl for the feedback. It will take me sometime before I get a working solution.

@kevinmungai
Copy link

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 expected

a 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

Execution error (IllegalArgumentException) at leona.schema/transform (schema.clj:110).
Don't know how to create ISeq from: clojure.lang.Keyword

what I have tried

I have tried to run the tests of leona but I get
Execution error (IllegalArgumentException) at leona.schema/transform (schema.clj:110).
Don't know how to create ISeq from: clojure.lang.Keyword

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.

@workshub
Copy link

workshub bot commented Sep 17, 2019

If you successfully complete this Issue via WorskHub there's a $75 reward available.
Start work via WorksHub Issue Details page.

@workshub
Copy link

workshub bot commented Sep 17, 2019

@umitduran started working on this issue via WorksHub.

@acron0
Copy link
Member Author

acron0 commented Sep 18, 2019

@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 IllegalArgumentException?

@workshub
Copy link

workshub bot commented Sep 25, 2019

@tolgraven started working on this issue via WorksHub.

tolgraven added a commit to tolgraven/leona that referenced this issue Sep 25, 2019
and WorksHub#11 (description support), both working but in need of tests
eetc and especially design decisions before any further work.
@workshub
Copy link

workshub bot commented Oct 4, 2019

An user started working on this issue via WorksHub.

@workshub
Copy link

workshub bot commented Oct 8, 2019

@chandanlal92 started working on this issue via WorksHub.

@workshub
Copy link

workshub bot commented Dec 4, 2019

@ynohtna82nosredna started working on this issue via WorksHub.

@workshub
Copy link

workshub bot commented Dec 19, 2019

A user started working on this issue via WorksHub.

@workshub
Copy link

workshub bot commented Feb 14, 2020

@wizzytod started working on this issue via WorksHub.

@wizzytod
Copy link

wizzytod commented Feb 19, 2020

Hi, @acron0 !

May I suggest using spec-tools to add a description for attach-query's query-spec?
E.g.

(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)
    ...)

@acron0
Copy link
Member Author

acron0 commented Jun 3, 2020

@wizzytod Yes, I would accept PR that connects the dots to make this work

@workshub
Copy link

workshub bot commented Dec 24, 2020

A user started working on this issue via WorksHub.

@workshub
Copy link

workshub bot commented Aug 12, 2021

@ansari691 started working on this issue via WorksHub.

@workshub
Copy link

workshub bot commented Feb 2, 2023

@benjamin-asdf started working on this issue via WorksHub.

@benjamin-asdf
Copy link
Contributor

benjamin-asdf commented Feb 4, 2023

  1. Adding descriptions to objects via metadata on resolver would make sense to me
  2. how to do descriptions for fields and args?
;; :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 compile it probably makes more sense that it is another attach- function.
Also for 1) we probably want that on the level of generating, not compiling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants