magidoc-org / magidoc

Autogenerate static GraphQL API documentation
https://magidoc.js.org
MIT License
250 stars 21 forks source link

Document how to add examples for responses or variables #390

Closed gentunian closed 3 months ago

gentunian commented 3 months ago

I've read the magidoc example for graphql schema and I compared the live demo. The live demo has examples on how responses or variables would be.

However, I don't see those examples in the schema file.

In my case, the example in variables and in response tabs are the name of the property. Imagine we have a property named active of type boolean then I see:

...
  "active": "active"
...
pelletier197 commented 3 months ago

Hi. Thank you for raising this issue. I'll try to answer those questions.

  1. Examples are automatically generated from your schema. They are not described anywhere in the configuration.

  2. For the active field, it should technically detect the field type and try to represent it we best as possible. If your field is indeed boolean and it outputs a string, this might be a bug. Would you be able to provide a reproduction schema ?

In the meantime, have a look at the query generation factory. This can help you override field outputs for those queries.

gentunian commented 3 months ago

Hi, @pelletier197 thanks for replying and clarifying.

Based on the live demo site Response tab:

image

and reading the repo example for spacex, I didn't find how to produce such output.

Now that you mention I do realize I made a mistake in my example. The type for active was String, my apologies for the confusion.

Still the case on how to produce such a Response with example data like the live demo is a mystery for me trying to find it in the schema file.

Thanks,

pelletier197 commented 3 months ago

I'm not sure I understand your question. This is done automatically on queries, mutations and subscriptions. You don't need to do anything.

gentunian commented 3 months ago

I pasted a screenshot on how the live demo shows an example for properties like id, orbit_duration_yr, sidewall_angle_deg with custom values. I was wondering if we can provide examples for those values like for REST APIs using OpenAPI. You can close the ticket if that's not possible so no documentation would be added because maybe there's no feature for it.

pelletier197 commented 3 months ago

So this is possible for request values as well as response values, using the factory configuration.

It is not done through the scheme itself, but through the configuration file.

gentunian commented 3 months ago

Thanks for clarifying, I'm closing this.