Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document a GraphQL API

With REST we can use Swagger, RAML or other technologies to document our API and generate an HTML documentation that our consumers can read without any need of interaction with the servers.

Does something similar exist for GraphQL? Is there any way to generate a documentation of resources and properties?

like image 982
Francisco Canela Avatar asked Sep 15 '16 07:09

Francisco Canela


People also ask

Is GraphQL self documenting?

GraphQL: a type system with a query language Then GraphQL itself is just a simple language to traverse the relationships between those types and express which fields you want to read on each object. This makes GraphQL inherently self-documenting.

What is document in GraphQL?

GraphQL document: A string written in the GraphQL language that defines one or more operations and fragments. Operation: A single query, mutation, or subscription that can be interpreted by a GraphQL execution engine.


2 Answers

It looks like there is now https://www.npmjs.com/package/graphql-docs

Dynamically generated documentation explorer for GraphQL schemas. It aims to provide a better overview of a schema than GraphiQL, but without querying features.

enter image description here

You can also generate a static documentation file based on a schema file or GraphQL endpoint:

npm install -g graphql-docs graphql-docs-gen http://GRAPHQL_ENDPOINT documentation.html 
like image 140
jun Avatar answered Dec 05 '22 22:12

jun


To my knowledge there is no tool yet that automatically generates HTML documentation for a GraphQL API, but I've found GraphiQL to be even more useful than any API documentation in HTML that I've seen.

GraphiQL lets you interactively explore the schema of a GraphQL server and run queries against it at the same time. It has syntax highlighting, autocompletion, and it even tells you when your query is invalid without executing it.

If you're looking for static documentation, I've found it pretty convenient to read the schema in GraphQL schema language. Thanks to another great feature of GraphQL - schema introspection - you can easily print the schema for any server you have access to. Simply run the introspection query against the server and then print the resulting introspection schema like so (using graphql-js):

var graphql = require('graphql'); var introspectionSchema = {}; // paste schema here console.log(graphql.printSchema(graphql.buildClientSchema(introspectionSchema))); 

The result will look something like this:

# An author type Author {   id: ID!    # First and last name of the author   name: String }  # The schema's root query type type Query {    # Find an author by name (must match exactly)   author(name: String!): Author } 
like image 45
helfer Avatar answered Dec 05 '22 21:12

helfer