Outputting GraphQL schemas to documentation (markdown file)

Hi all - is there a way to output graphql schemas to markdown files?

Thank you!

Hey there @ktn_chowry , welcome to the Dgraph community! We hope you enjoy your stay.

Your question isn’t that clear. Perhaps one way to do it is something like this:

$ curl 'https://ENDPOINT_OF_/graphql' -H 'Content-Type: application/json' -H 'Accept: application/json' --compressed -d '
{
  __schema{
    types {
      name 
      kind
    }
  }
}' | sed -i '1s;^;```\n;' | sed -i '$ a ```\n' > doc.md

Let me break it down for you:

$ curl 'https://ENDPOINT_OF_/graphql' -H 'Content-Type: application/json' -H 'Accept: application/json' --compressed -d

This line is the curl magic incantation to get your GraphQL schema

'
{
  __schema{
    types {
      name 
      kind
    }
  }
}'

This snippet is the actual query to get your graphql schema

| sed -i '1s;^;```\n;' 

Here, we use sed to add ``` to the top of the file

| sed -i '$ a ```\n'

Here we use sed to add ``` to the end of the file

> doc.md

And here we redirect the output to a file named doc.md