GithubHelp home page GithubHelp logo

brettchalupa / graphql-docs Goto Github PK

View Code? Open in Web Editor NEW
505.0 8.0 64.0 2.91 MB

Easily generate beautiful documentation from your GraphQL schema.

License: MIT License

Ruby 59.35% Shell 0.21% HTML 13.25% SCSS 27.20%
graphql documentation ruby good-first-issue

graphql-docs's Introduction

GraphQLDocs

Ruby library and CLI for easily generating beautiful documentation from your GraphQL schema.

sample

Installation

Add the gem to your project with this command:

bundle add graphql-docs

Or install it yourself as:

gem install graphql-docs

Usage

GraphQLDocs can be used as a Ruby library to build the documentation website. Using it as a Ruby library allows for more control and using every supported option. Here's an example:

# pass in a filename
GraphQLDocs.build(filename: filename)

# or pass in a string
GraphQLDocs.build(schema: contents)

# or a schema class
schema = GraphQL::Schema.define do
  query query_type
end
GraphQLDocs.build(schema: schema)

GraphQLDocs also has a simplified CLI (graphql-docs) that gets installed with the gem:

graphql-docs schema.graphql

That will generate the output in the output dir.

See all of the supported CLI options with:

graphql-docs -h

Breakdown

There are several phases going on the single GraphQLDocs.build call:

  • The GraphQL IDL file is read (if you passed filename) through GraphQL::Client (or simply read if you passed a string through schema).
  • GraphQL::Parser manipulates the IDL into a slightly saner format.
  • GraphQL::Generator takes that saner format and begins the process of applying items to the HTML templates.
  • GraphQL::Renderer technically runs as part of the generation phase. It passes the contents of each page and converts it into HTML.

If you wanted to, you could break these calls up individually. For example:

options = {}
options[:filename] = "#{File.dirname(__FILE__)}/../data/graphql/schema.idl"
options[:renderer] = MySuperCoolRenderer

options = GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge(options)

response = File.read(options[:filename])

parser = GraphQLDocs::Parser.new(response, options)
parsed_schema = parser.parse

generator = GraphQLDocs::Generator.new(parsed_schema, options)

generator.generate

Generating output

By default, the HTML generation process uses ERB to layout the content. There are a bunch of default options provided for you, but feel free to override any of these. The Configuration section below has more information on what you can change.

It also uses html-pipeline to perform the rendering by default. You can override this by providing a custom rendering class.You must implement two methods:

  • initialize - Takes two arguments, the parsed schema and the configuration options.
  • render Takes the contents of a template page. It also takes two optional kwargs, the GraphQL type and its name. For example:
class CustomRenderer
  def initialize(parsed_schema, options)
    @parsed_schema = parsed_schema
    @options = options
  end

  def render(contents, type: nil, name: nil)
    contents.sub(/Repository/i, '<strong>Meow Woof!</strong>')

    opts[:content] = contents
    @graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding })
  end
end

options[:filename] = 'location/to/sw-api.graphql'
options[:renderer] = CustomRenderer

GraphQLDocs.build(options)

If your render method returns nil, the Generator will not attempt to write any HTML file.

Templates

The layouts for the individual GraphQL pages are ERB templates, but you can also use ERB templates for your static landing pages.

If you want to add additional variables for your landing pages, you can add define a variables hash within the landing_pages option.

Helper methods

In your ERB layouts, there are several helper methods you can use. The helper methods are:

  • slugify(str) - This slugifies the given string.
  • include(filename, opts) - This embeds a template from your includes folder, passing along the local options provided.
  • markdownify(string) - This converts a string into HTML via CommonMarker.
  • graphql_operation_types, graphql_mutation_types, graphql_object_types, graphql_interface_types, graphql_enum_types, graphql_union_types, graphql_input_object_types, graphql_scalar_types, graphql_directive_types - Collections of the various GraphQL types.

To call these methods within templates, you must use the dot notation, such as <%= slugify.(text) %>.

Configuration

The following options are available:

Option Description Default
filename The location of your schema's IDL file. nil
schema A string representing a schema IDL file. nil
output_dir The location of the output HTML. ./output/
use_default_styles Indicates if you want to use the default styles. true
base_url Indicates the base URL to prepend for assets and links. ""
delete_output Deletes output_dir before generating content. false
pipeline_config Defines two sub-keys, pipeline and context, which are used by html-pipeline when rendering your output. pipeline has ExtendedMarkdownFilter, EmojiFilter, and TableOfContentsFilter. context has gfm: false and asset_root set to GitHub's CDN.
renderer The rendering class to use. GraphQLDocs::Renderer
templates The templates to use when generating HTML. You may override any of the following keys: default, includes, operations, objects, mutations, interfaces, enums, unions, input_objects, scalars, directives. The defaults are found in lib/graphql-docs/layouts/.
landing_pages The landing page to use when generating HTML for each type. You may override any of the following keys: index, query, object, mutation, interface, enum, union, input_object, scalar, directive. The defaults are found in lib/graphql-docs/landing_pages/.
classes Additional class names you can provide to certain elements. The full list is available in lib/graphql-docs/configuration.rb.
notices A proc used to add notices to schema members. See Customizing Notices section below. nil

Customizing Notices

A notice is a block of CommonMark text that optionally has a title which is displayed above a schema member's description. The look of a notice block can be controlled by specifying a custom class for it and then styled via CSS.

The notices option allows you to customize the notices that appear for a specific schema member using a proc.

The proc will be called for each schema member and needs to return an array of notices or an empty array if there are none.

A notice has the following options:

Option Description
body CommonMark body of the notice
title Optional title of the notice
class Optional CSS class for the wrapper <div> of the notice
title_class Optional CSS class for the <span> of the notice's title

Example of a notices proc that adds a notice to the TeamDiscussion type:

options[:notices] = ->(schema_member_path) {
  notices = []

  if schema_member_path == "TeamDiscussion"
    notices << {
      class: "preview-notice",
      body: "Available via the [Team Discussion](/previews/team-discussion) preview.",
    }
  end

  notices
}

The format of schema_member_path is a dot delimited path to the schema member. For example:

"Author", # an object
"ExtraInfo" # an interface,
"Author.socialSecurityNumber" # a field
"Book.author.includeMiddleInitial" # an argument
"Likeable" # a union,
"Cover" # an enum
"Cover.DIGITAL" # an enum value
"BookOrder" # an input object
"Mutation.addLike" # a mutation

Supported Ruby Versions

The gem officially supports Ruby 2.7 and newer.

A note about Ruby 2.6: It works, but it requires activesupport to be set to a version less than 7 due to it dropping Ruby 2.6 support. Ruby 2.6 is no longer tested on CI.

Any dropping of Ruby version support is considered a breaking change and means a major release for the gem.

Upgrading

This project aims to strictly follow Semantic Versioning. Minor and patch level updates can be done with pretty high confidence that your usage won't break.

Review the Changelog for detailed changes for each release. The intent is to make upgrading as painless as possible.

Roadmap

Upcoming work for the project is organized publicly via GitHub Projects.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Sample Site

Clone this repository and run:

bin/rake sample:generate

to see some sample output in the output dir.

Boot up a server to view it:

bin/rake sample:serve

Credits

Originally built by gjtorikian. Actively maintained by brettchalupa.

graphql-docs's People

Contributors

alecslupu avatar bbugh avatar bethsebian avatar brettchalupa avatar bswinnerton avatar cjoudrey avatar cmatheson avatar eugenk avatar gjtorikian avatar hibariya avatar ind1go avatar jeromedalbert avatar joanln avatar leenday avatar nicolasleger avatar obrie avatar olivercaine avatar piotrze avatar sarahs avatar thebadmonkeydev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-docs's Issues

"no implicit conversion of Faraday::Response into String"

I tried to point this at my dev server:

task :graphql_docs do
  begin
    GraphQLDocs.build(url: "http://resources.pco.dev/graphql")
  rescue StandardError => err
    puts err.message
    puts err.backtrace
  end
end

but I got an error:

~/code/resources $ be rake graphql_docs
no implicit conversion of Faraday::Response into String
/Users/rmosolgo/.rbenv/versions/2.3.3/lib/ruby/2.3.0/json/common.rb:156:in `initialize'
/Users/rmosolgo/.rbenv/versions/2.3.3/lib/ruby/2.3.0/json/common.rb:156:in `new'
/Users/rmosolgo/.rbenv/versions/2.3.3/lib/ruby/2.3.0/json/common.rb:156:in `parse'
/Users/rmosolgo/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/graphql-docs-0.1.1/lib/graphql-docs/parser.rb:7:in `initialize'
/Users/rmosolgo/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/graphql-docs-0.1.1/lib/graphql-docs.rb:33:in `new'
/Users/rmosolgo/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/graphql-docs-0.1.1/lib/graphql-docs.rb:33:in `build'
/Users/rmosolgo/code/resources/Rakefile:13:in `block in <top (required)>'

I worked around it with this monkey-patch:

  class GraphQLDocs::Client 
    def fetch 
+     res = @faraday.post do |req|
-     @faraday.post do |req|
        req.headers['Content-Type'] = 'application/json'
        req.body = "{ \"query\": \"#{GraphQL::Introspection::INTROSPECTION_QUERY.gsub("\n", '')}\" }"
      end
+     res.body
    end 
  end 

Would that be a good addition here? Or was there an error on my end?

Queries section is missing

When I generate, the queries page (operation/query/index.html) doesn't get created, resulting in broken links.

graphql-docs doesn't generate Mutation listing

For some reason when using graphql-docs I can't get it to generate the mutation listing properly.

I discovered it when I couldn't get it to work properly for our own schema but even when running bundle exec rake sample the mutation landing page is blank even though the Query page lists the correct queries and the site hosted at https://www.gjtorikian.com/graphql-docs/object/mutation/ lists them correctly.

Is this a bug or am I doing something wrong?

Landing pages as ERB templates

Is there any way to use erb templates for landing pages instead of plain markdown files? Would like to localize the static text but not seeing any obvious way.

Feature: Rendering/Listing directives on a field/type/etc

Tool supports rendering deprecation notices based on the @deprecated directive. It would be nice to support other directives. An example specific to one of our projects: we have a @authorize(scope: 'some-scope') custom directive that does some up front authorization and it would great if the docs could render something alongside the fields annotated with this.

Haven't spent enough time looking at this code to truly see if this is quick and easy and I'm not sure if there is a simple solution. For documentation purposes, each directive can have documentation on it like all other items get so you could have a side-panel section called Directives that lists the directives they'll encounter with a description of what each means. Then each field that is annotated with a directive could just link to the appropriate page for details and print the directive as it's found in the schema maybe?

Open to ideas as to how to resolve this and I could try my hand at some ruby!

Take a GraphQL::Schema as input?

I'd like to build docs in the same Ruby process where the GraphQL::Schema is. Would you accept an API that takes input from an in-memory source? Maybe

result_hash = MySchema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
GraphQLDocs.build(introspection_result: result_hash)

or

GraphQLDocs.build(schema: MySchema)

For now, I'm writing to an intermediate file:

    res = ResourcesSchema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
    File.write("./__GraphQL", JSON.dump(res))
    GraphQLDocs.build(path: "./__GraphQL")

Support relative urls by default

Thanks for making this! I was wondering shall we make it possible to support relative urls by default ? Right now if I generate in a directory it is looks pretty bad because it uses / in front of its urls.

Yard uses relative urls and there forsakes it easy to put docs in in a separate folder. i.e docs/graphql

Support for quote-styled comment

When parsing content with quote-styled comment such as """The ID of user""" , it throws an error
Parse error on "id" (IDENTIFIER) at [9, 3] (GraphQL::ParseError)

It is possible to support that?

Re-establish RuboCop usage for linting

Tasks:

  • be specific about RuboCop gem vers so it isn't a moving target
  • add minitest ext
  • address autocorrectable offenses
  • address other manual offenses
  • make default rake task run RuboCop for easy running w/ tests
  • document its usage in CONTRIBUTING
  • get it working on CI

Integrate with Jekyll (feature)

Is it possible to integrate this with Jekyll?

My Ruby skills are not good (non-existent), but is there a way to get this to work with a Jekyll generator plugin (https://jekyllrb.com/docs/plugins/generators/) so Jekyll could create Pages using its own layouts? I'd imagine the sidebar would need to be created as some form of "site data" that could be iterated through to render a sidebar too.

Thanks.

demo page broken

GET https://www.gjtorikian.com/assets/style.css net::ERR_ABORTED 404

Whitespace formatting removed from schema during parser initialization

When creating a parser during document creation using our schema the initialization strips away whitespace formatting in our descriptions.

I think it's the Graphql-ruby gem doing from_definition

@schema = GraphQL::Schema.from_definition(schema)

This is an issue as we are trying to add formatted code blocks to our descriptions and this step is removing all of our leading whitespace within the block. As a hack we are overwriting with our original
schema

parser.instance_variable_set(:@schema, PlatformVsArenaSchema)

before calling

parser.parse

If open to supporting having the parser take a graphql::schema object in some manner I can work on some ideas and make a PR?

Installation/gem dependency failure "commonmarker"

Hi, I installed the gem in the standard way in our Gemfile gem 'graphql-docs', then started the rails console to try out the example. It failed with an error message about missing gem dependency commonmarker:

.../.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:84:in `rescue in block \ 
  (2 levels) in require': There was an error while trying to load the gem 'graphql-docs'.
Gem Load Error is: Missing dependency 'commonmarker' for MarkdownFilter. See README.md for details.
LoadError: cannot load such file -- commonmarker

Adding gem 'commonmarker' to the Gemfile fixed the issue. However, this seems to be a problem with the gem require dependency, as we're not using the MarkdownFilter (I don't think?)

Thanks! Loving the gem html output more than the alternatives.

Support class based GraphQL

Hello,

Is this gem compatible with class based definitions? I attempted to use it but I quickly ran into issues. In the parser I see things like

if schema.is_a?(GraphQL::Schema)

Regards,

Address `gem build` issues

WARNING:  open-ended dependency on awesome_print (>= 0, development) is not recommended
  use a bounded requirement, such as '~> x.y'
WARNING:  open-ended dependency on rake (>= 0, development) is not recommended
  use a bounded requirement, such as '~> x.y'
WARNING:  open-ended dependency on rubocop (>= 0, development) is not recommended
  use a bounded requirement, such as '~> x.y'
WARNING:  open-ended dependency on rubocop-performance (>= 0, development) is not recommende
  use a bounded requirement, such as '~> x.y'
WARNING:  open-ended dependency on rubocop-standard (>= 0, development) is not recommended
  use a bounded requirement, such as '~> x.y'
WARNING:  See https://guides.rubygems.org/specification-reference/ for help
  Successfully built RubyGem
  Name: graphql-docs
  Version: 3.0.1
  File: graphql-docs-3.0.1.gem

Sidebar as separate file?

Is there a way to generate sidebar as separate file?

I've tried to use erb markups in landing pages in order to generate list of items, but with no luck.

relative hrefs in included layouts

I had some issues with links going to relative places with the up-one-levels

<a href="../../object/mutation" class="sidebar-link<% if title == "Mutation" %> current<% end %>">

Are the docs intended to be embedded on a site, or served as a standalone site?

Either way I think it would be useful to express the paths as relative to the site root and optionally prefixed with some user configurable path

<user_prefix>/object/objectname

What do you think?

Mountable Rack app for dynamic requests

It'd be great if the GraphQL docs had a server that ccould be mounted in Rails (or whatever framework) and handle requests. This would make the development process really nice where the docs wouldn't have to be regenerated over and over to view them as things are changing. It may be slow? I'm not sure. This could be quite a large change. But it would be nice for development at least instead of relying upon SSG.

"*** No sourcefile available for (erb)" error when attempting to customize template

I'm attempting to customize the objects template (to add an "Examples" section). To do this I made a copy of the graphql_objects.html file in my project, and then tried:

GraphQLDocs.build(
   ...
   templates: { objects:  OBJECT_TEMPLATE_PATH.to_s },
   ...
}

...where OBJECT_TEMPLATE_PATH points to my local copy of the objects template. Since that fails and seems to erase the other templates as well, I tried this instead:

opts = GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS 
GraphQLDocs.build(
   ...
   templates: opts[:templates].merge(objects: OBJECT_TEMPLATE_PATH.to_s),
   ...
}

I've confirmed that the local template file is readable. But when I execute this I get this error:

  *** No sourcefile available for (erb)  

It is raised on this line of GraphQLDocs::Generator#create_graphql_object_pages. Tracing it into ERB, the error occurs on line 850 of erb.rb:

 eval(@src, b, (@filename || '(erb)'), 0)  

This not a normal Ruby error, in that it cannot be trapped in a rescue block.

It appears that the only difference between a working configuration and one that fails with this error is that the failing version points to a local project copy of that template file, rather than the copy in the gem.

Am I setting the opts[:templates][:objects] key incorrectly?

Any suggestions appreciated. Thanks for this very useful gem.

How to generate schema content?

From the Readme:

GraphQLDocs.build(schema: contents)

How do I generate contents? Should this work?

> GraphQLDocs.build(schema: GraphQL::Schema::Printer.print_schema(MySchema))
GraphQL::ParseError: Parse error on "}" (RCURLY) at [1468, 1]                                             
from parser.y:442:in `on_error'                                                                          

but then maybe something in MySchema is broken? Is this diagnostic?

> GraphQL.parse(GraphQL::Schema::Printer.print_schema(MySchema))    
GraphQL::ParseError: Parse error on "}" (RCURLY) at [1468, 1]                                      
from parser.y:442:in `on_error'                                                                    

MySchema is working fine for generating query results. Can it work for queries but still be broken for parsing? How would I go about debugging that? Or am I generating the contents incorrectly?

Thanks ...

Ruby sass is deprecated

I noticed that this project uses the old sass gem. When I install graphql-docs, it complains that this gem is deprecated, etc. There's more info on the deprecation here.

Looks like sassc is suggested as a drop-in replacement. Any possibility that we could switch over?

Add Rake task for generating docs

I'd like to be able to run something like rake graphql:docs:generate or something similar to run the generator for the docs site.

This would allow people to hook into other Rake tasks to generate the site. Example: Rake::Task["assets:precompile"].enhance(["graphql:docs:generate"])

Tasks:

  • build this out
  • write tests for the rake task
  • document it

Refresh demo

Tasks:

  • set up a new URL for the demo -- can it just be a github.io URL?
  • get the demo site automatically building and updating via CI
  • see if a simpler/smaller demo might be easier for viewing/exploring/demo

Legacy `.graphql_definition` objects are deprecated and will be removed in GraphQL-Ruby 2.0. Remove `.graphql_definition` to use a class-based definition instead.

Is this gem being maintained?

Called on #<GraphQL::Schema::NonNull @of_type=#<GraphQL::Schema::List:0x00007f78fdd6c4f0 @of_type=#<GraphQL::Schema::NonNull @of_type=#<Class:0x00007f78fdd6f8d0>>, @to_non_null_type=#<GraphQL::Schema::NonNull @of_type=#<GraphQL::Schema::List:0x00007f78fdd6c4f0 ...>>>> from:
   /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs/parser.rb:220:in `generate_type'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs/parser.rb:170:in `block in fetch_fields'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs/parser.rb:159:in `each_value'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs/parser.rb:159:in `fetch_fields'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs/parser.rb:78:in `block in parse'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs/parser.rb:42:in `each_value'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs/parser.rb:42:in `parse'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/graphql-docs-2.0.1/lib/graphql-docs.rb:48:in `build'
  obfuscated.rake:7:in `block (2 levels) in <main>'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/railties-6.1.4.4/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
  /Users/joel/.rvm/gems/ruby-3.0.3/gems/railties-6.1.4.4/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
[master 78ac8f8] forcing year, should break tests
 1 file changed, 4 insertions(+), 1 deletion(-)

Exception when description uses unicode character

When my GraphQL schema contains unicode characters, or their HTML entity equivalents, I'm unable to render documentation. I encountered the same error for &mdash;, โ€ and โ€œ

I get the following error:

Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
(erb):34:in `block in render'
/Users/fried/.rvm/gems/ruby-2.6.3@developer-4me-com/gems/graphql-docs-2.0.0/lib/graphql-docs/renderer.rb:48:in `render'
/Users/fried/.rvm/gems/ruby-2.6.3@developer-4me-com/gems/graphql-docs-2.0.0/lib/graphql-docs/generator.rb:225:in `write_file'
/Users/fried/.rvm/gems/ruby-2.6.3@developer-4me-com/gems/graphql-docs-2.0.0/lib/graphql-docs/generator.rb:126:in `block in create_graphql_object_pages'
/Users/fried/.rvm/gems/ruby-2.6.3@developer-4me-com/gems/graphql-docs-2.0.0/lib/graphql-docs/generator.rb:122:in `each'
/Users/fried/.rvm/gems/ruby-2.6.3@developer-4me-com/gems/graphql-docs-2.0.0/lib/graphql-docs/generator.rb:122:in `create_graphql_object_pages'
/Users/fried/.rvm/gems/ruby-2.6.3@developer-4me-com/gems/graphql-docs-2.0.0/lib/graphql-docs/generator.rb:54:in `generate'
/Users/fried/.rvm/gems/ruby-2.6.3@developer-4me-com/gems/graphql-docs-2.0.0/lib/graphql-docs.rb:52:in `build'

(Error remains the same after upgrading to 2.0.1)

Erroneous <pre> tag in rendered output

I'm getting erroneous <pre> tags in the output of field descriptions and interface lists. I've been able to reproduce this by making a clean clone and running bundle exec rake sample

screenshot1

Notice in the screenshot how the a, code, and li tags are all clobbered by surrounding <pre> and <code> tags:

screenshot2

Parser cannot handle scalar input for Mutation fields

The parser fails if the input of a mutation has a scalar field.

schema = <<SCHEMA
type Query {
  foo : ID
}
type Mutation {
  bar(input: ID!) : ID
}
SCHEMA

GraphQLDocs.build(schema: schema)

NoMethodError: undefined method `input_fields' for ID:GraphQL::ScalarType
from ~/.gem/ruby/2.5.0/gems/graphql-docs-1.0.1/lib/graphql-docs/parser.rb:48:in `block (2 levels) in parse'

Tested with ruby 2.5.0 and graphql-docs 1.0.1.

Documentation sections

Let's say each comment around field and definitions is an entity. Is it possible to group those entities in some logical sections?

e.g. group documentation regarding Credentials in 1 sections and other data in another. So they are all not generated always in Queries/Mutations, but

-> Queries -> Credentials section
-> Mutation -> Credentials section

or

-> Credentials:
-> Queries
-> Mutations

Remove reliance upon bash in the bin dir

It would be great if the the bin/ scripts were Ruby instead of Bash/Shell scripts so that they're more cross-platform. This would make it easier for Windows users to contribute.

Sidebar search

It'd be nice to be able to search through all of the concepts in the sidebar. I think this would be a really simplistic client-side JS search through the current DOM elements.

Output of queries is missing

The output of mutations is generated under: mutation/mutationName/index.html, but all the query/queryName are missing.

It only generates /operation/query/index.html which is about the root query type.

Undefined method each for nil:NilClass (helpers.rb)

I have a rake task that attempts to generate documentation from an already built schema file:

task :docs, [:schema_path, :output_path] => :environment do |t, args|
    args.with_defaults(schema_path: 'data/schema.json')
    args.with_defaults(output_path: 'docs')

    schema_path = Rails.root.join(args.schema_path)
    unless File.exist?(schema_path)
      puts 'Schema does not exist, generating...'
      Rake::Task['graphql:schema'].invoke(schema_path)
    end

    GraphQLDocs.build(path: schema_path, output_dir: args.output_path, base_url: '', delete_output: true)
  end

However it fails with the following error:

** Invoke graphql:docs (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute graphql:docs
rake aborted!
NoMethodError: undefined method `each' for nil:NilClass
(erb):112:in `block in include'
/usr/local/lib/ruby/2.4.0/erb.rb:896:in `eval'
/usr/local/lib/ruby/2.4.0/erb.rb:896:in `result'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs/helpers.rb:16:in `include'
(erb):30:in `call'
(erb):30:in `block in render'
/usr/local/lib/ruby/2.4.0/erb.rb:896:in `eval'
/usr/local/lib/ruby/2.4.0/erb.rb:896:in `result'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs/renderer.rb:49:in `render'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs/generator.rb:191:in `write_file'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs/generator.rb:109:in `block in create_graphql_object_pages'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs/generator.rb:83:in `each'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs/generator.rb:83:in `create_graphql_object_pages'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs/generator.rb:28:in `generate'
/usr/local/bundle/gems/graphql-docs-0.5.2/lib/graphql-docs.rb:39:in `build'
/doctor-finder/lib/tasks/graphql.rake:25:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/task.rb:248:in `block in execute'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/task.rb:243:in `each'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/task.rb:243:in `execute'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/task.rb:173:in `invoke'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:152:in `invoke_task'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:108:in `each'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:108:in `block in top_level'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:102:in `top_level'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:80:in `block in run'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/bundle/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
/usr/local/bundle/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/rake:17:in `load'
/usr/local/bundle/bin/rake:17:in `<main>'
Tasks: TOP => graphql:docs

Here is the schema file if you would like to attempt to reproduce the error.

Documentation contents replaced with "<!-- raw HTML omitted -->"

After not generating our GraphQL docs for a few months we tried it again and found that much of the contents of our object pages have been replaced with multiple lines of

<!-- raw HTML omitted -->

... instead of the previous contents. Grepping around it looks like this text comes from the CommonMarker gem. That gem generates these notices when given a string that includes HTML, and when called with the :DEAFULT option, rather than the :UNSAFE option.

Changing that option on this line is not enough to fix the problem. It seems that the markdown is mostly parsed via the ExtendedMarkdownFilter object, and I haven't yet figured out how to fix the output of that. That gem doesn't call CommonMarker.render_html the way that this gem does. It does add the commonmarker dependency, but I'm not seeing how it's used there.

Perhaps this bug is a result of a recent change to the CommonMarker gem? That gem reached version 0.18.x on October 17th. The fix may be pinning to an older version of CommonMarker, or maybe changing the options to :UNSAFE from :DEFAULT in this gem and in extended-markdown-filter.

Option to use relative URLs

Have you considered the ability to be able to generate with relative URLs rather than a known root?

We deploy to multiple different environments and the base URL changes between those. We'd like to just build once for all environments.

I don't know whether this is already possible through customising the layouts and overriding templates, but I'm not sure how - whether there's some context variable that html-pipeline carries around to determine how deep the current HTML file is nested. If you've got insight here, I'd love to hear that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.