Module: GraphQLDocs
- Defined in:
- lib/graphql-docs.rb,
lib/graphql-docs/parser.rb,
lib/graphql-docs/helpers.rb,
lib/graphql-docs/version.rb,
lib/graphql-docs/renderer.rb,
lib/graphql-docs/generator.rb,
lib/graphql-docs/configuration.rb
Overview
GraphQLDocs is a library for generating beautiful HTML documentation from GraphQL schemas. It parses GraphQL schema files or schema objects and generates a complete documentation website with customizable templates and styling.
Defined Under Namespace
Modules: Configuration, Helpers Classes: Generator, Parser, Renderer
Constant Summary collapse
- VERSION =
Current version of the GraphQLDocs gem
'5.2.0'
Class Method Summary collapse
-
.build(options) ⇒ Boolean
Builds HTML documentation from a GraphQL schema.
Class Method Details
.build(options) ⇒ Boolean
Builds HTML documentation from a GraphQL schema.
This is the main entry point for generating documentation. It accepts either a schema file path or a schema string/object, parses it, and generates a complete HTML documentation website.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/graphql-docs.rb', line 73 def build() # do not let user provided values overwrite every single value %i[templates landing_pages].each do |opt| next unless .key?(opt) GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS[opt].each_pair do |key, value| [opt][key] = value unless [opt].key?(key) end end = GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge() filename = [:filename] schema = [:schema] raise ArgumentError, 'Pass in `filename` or `schema`, but not both!' if !filename.nil? && !schema.nil? raise ArgumentError, 'Pass in either `filename` or `schema`' if filename.nil? && schema.nil? if filename raise TypeError, "Expected `String`, got `#{filename.class}`" unless filename.is_a?(String) raise ArgumentError, "#{filename} does not exist!" unless File.exist?(filename) schema = File.read(filename) else raise TypeError, "Expected `String` or `GraphQL::Schema`, got `#{schema.class}`" if !schema.is_a?(String) && !schema_type?(schema) schema = schema end parser = GraphQLDocs::Parser.new(schema, ) parsed_schema = parser.parse generator = GraphQLDocs::Generator.new(parsed_schema, ) generator.generate end |