├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── tests.yml ├── .gitignore ├── .rubocop.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── console ├── rake └── setup ├── exe └── graphql-docs ├── graphql-docs.gemspec ├── lib ├── graphql-docs.rb └── graphql-docs │ ├── configuration.rb │ ├── generator.rb │ ├── helpers.rb │ ├── landing_pages │ ├── directive.md │ ├── enum.md │ ├── index.md │ ├── input_object.md │ ├── interface.md │ ├── mutation.md │ ├── object.md │ ├── query.md │ ├── scalar.md │ └── union.md │ ├── layouts │ ├── assets │ │ ├── _sass │ │ │ ├── _api-box.scss │ │ │ ├── _content.scss │ │ │ ├── _deprecations.scss │ │ │ ├── _fonts.scss │ │ │ ├── _header.scss │ │ │ ├── _mobile.scss │ │ │ ├── _normalize.scss │ │ │ ├── _search.scss │ │ │ ├── _sidebar.scss │ │ │ ├── _syntax.scss │ │ │ └── _types.scss │ │ ├── css │ │ │ └── screen.scss │ │ ├── images │ │ │ ├── graphiql-headers.png │ │ │ ├── graphiql-variables.png │ │ │ ├── graphiql.png │ │ │ ├── menu.png │ │ │ ├── navbar.png │ │ │ └── search.svg │ │ └── webfonts │ │ │ ├── 2C4B9D_B_0.eot │ │ │ ├── 2C4B9D_B_0.ttf │ │ │ ├── 2C4B9D_B_0.woff │ │ │ ├── 2C4B9D_B_0.woff2 │ │ │ ├── 2C4B9D_C_0.eot │ │ │ ├── 2C4B9D_C_0.ttf │ │ │ ├── 2C4B9D_C_0.woff │ │ │ ├── 2C4B9D_C_0.woff2 │ │ │ ├── 2C4B9D_D_0.eot │ │ │ ├── 2C4B9D_D_0.ttf │ │ │ ├── 2C4B9D_D_0.woff │ │ │ ├── 2C4B9D_D_0.woff2 │ │ │ ├── 2C4B9D_E_0.eot │ │ │ ├── 2C4B9D_E_0.ttf │ │ │ ├── 2C4B9D_E_0.woff │ │ │ └── 2C4B9D_E_0.woff2 │ ├── default.html │ ├── graphql_directives.html │ ├── graphql_enums.html │ ├── graphql_input_objects.html │ ├── graphql_interfaces.html │ ├── graphql_mutations.html │ ├── graphql_objects.html │ ├── graphql_operations.html │ ├── graphql_queries.html │ ├── graphql_scalars.html │ ├── graphql_unions.html │ └── includes │ │ ├── arguments.html │ │ ├── connections.html │ │ ├── deprecations.html │ │ ├── fields.html │ │ ├── input_fields.html │ │ ├── locations.html │ │ ├── notices.html │ │ ├── possible_types.html │ │ ├── sidebar.html │ │ └── values.html │ ├── parser.rb │ ├── renderer.rb │ └── version.rb └── test ├── cli_test.rb ├── graphql-docs ├── fixtures │ ├── gh-schema.graphql │ ├── landing_pages │ │ ├── broken_yaml.md │ │ ├── object.erb │ │ └── whitespace_template.md │ ├── sw-schema.graphql │ └── tiny-schema.graphql ├── generator_test.rb ├── graphql-docs_test.rb ├── parser_test.rb └── renderer_test.rb └── test_helper.rb /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Do x 16 | 2. Do y 17 | 18 | **Expected behavior** 19 | A clear and concise description of what you expected to happen. 20 | 21 | **Screenshots** 22 | If applicable, add screenshots to help explain your problem. 23 | 24 | **Additional context** 25 | Add any other context about the problem here. 26 | 27 | Examples: 28 | 29 | - Source code 30 | - Version of gem being used 31 | - Ruby version 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Ruby 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | ruby-version: [3.4, 3.3, 3.2, 3.1] 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up Ruby ${{ matrix.ruby-version }} 17 | uses: ruby/setup-ruby@v1 18 | with: 19 | ruby-version: ${{ matrix.ruby-version }} 20 | bundler-cache: true 21 | - name: Run test suite 22 | run: bundle exec rake 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | /output/ 11 | /test/graphql-docs/fixtures/output/ 12 | /.sass-cache/ 13 | /output/ 14 | .byebug_history 15 | *.gem 16 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: rubocop-performance 2 | 3 | Style/StringLiterals: 4 | Enabled: true 5 | EnforcedStyle: single_quotes 6 | 7 | Naming/FileName: 8 | Enabled: false 9 | 10 | Layout/IndentationWidth: 11 | Width: 2 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # graphql-docs Changelog 2 | 3 | A concise overview of the public-facing changes to the gem from version to version. Does not include internal changes to the dev experience for the gem. 4 | 5 | ## Unreleased 6 | 7 | ## v5.2.0 - 2025-02-09 8 | 9 | - Add search filter to sidebar. Thanks @denisahearn! 10 | 11 | ## v5.1.0 - 2024-12-09 12 | 13 | - List queries in the sidebar, similar to mutations. See https://github.com/brettchalupa/graphql-docs/pull/156. Thanks @denisahearn! 14 | - Fix Sass `@import` deprecation 15 | - Add ostruct and logger gems to dependencies since they're being removed from the Ruby standard library in a future release 16 | - Test and fixture improvements 17 | 18 | ## v5.0.0 - 2024-07-03 19 | 20 | - **breaking**: The graphql gem 2.2.0+ breaks some of the parsing and displaying of comments from a GraphQL schema file 21 | - **breaking**: Ruby 2.6, 2.7, 3.0 are no longer supported as they are End of Life (EOL) 22 | - feat: CLI version flag: `graphql-docs --version` / `graphql-docs -v` 23 | - fix: CLI now works outside of a Bundler project 24 | - fix: test suite 25 | - chore: switch to sess-embedded gem for more maintained dependency 26 | 27 | ## v4.0.0 - 2023-01-26 28 | 29 | - **Breaking change**: drop support for Ruby 2.5 and earlier 30 | - CLI with limited options, e.g. `graphql-docs schema.graphql` 31 | - Dart Sass replaces Ruby Sass because Ruby Sass is deprecated 32 | - Fixes: 33 | - Upgrade commonmarker to latest ver to address security vulnerabilities 34 | - commonmarker pinned to version without security vulnerability 35 | - Chores: 36 | - Dev env refresh 37 | 38 | ## v3.0.1 - 2022-10-14 39 | 40 | - fix: Relieves `EscapeUtils.escape_html is deprecated. Use GCI.escapeHTML instead, it's faster` deprecation warning until it gets released in an downstream dependency 41 | - meta: Maintainership change from [gjtorikian](https://github.com/gjtorikian) to [brettchalupa](https://github.com/brettchalupa) 42 | 43 | ## v3.0.0 - 2022-03-23 44 | 45 | - Upgrades `graphql` gem to the 2.x series 46 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to a positive environment for our community include: 12 | 13 | * Demonstrating empathy and kindness toward other people 14 | * Being respectful of differing opinions, viewpoints, and experiences 15 | * Giving and gracefully accepting constructive feedback 16 | * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 17 | * Focusing on what is best not just for us as individuals, but for the overall community 18 | 19 | Examples of unacceptable behavior include: 20 | 21 | * The use of sexualized language or imagery, and sexual attention or 22 | advances of any kind 23 | * Trolling, insulting or derogatory comments, and personal or political attacks 24 | * Public or private harassment 25 | * Publishing others' private information, such as a physical or email 26 | address, without their explicit permission 27 | * Other conduct which could reasonably be considered inappropriate in a 28 | professional setting 29 | 30 | ## Enforcement Responsibilities 31 | 32 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 33 | 34 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 35 | 36 | ## Scope 37 | 38 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 39 | 40 | ## Enforcement 41 | 42 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at brettchalupa@gmail.com. All complaints will be reviewed and investigated promptly and fairly. 43 | 44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 45 | 46 | ## Enforcement Guidelines 47 | 48 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 49 | 50 | ### 1. Correction 51 | 52 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 53 | 54 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 55 | 56 | ### 2. Warning 57 | 58 | **Community Impact**: A violation through a single incident or series of actions. 59 | 60 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 61 | 62 | ### 3. Temporary Ban 63 | 64 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 65 | 66 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 67 | 68 | ### 4. Permanent Ban 69 | 70 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 71 | 72 | **Consequence**: A permanent ban from any sort of public interaction within the community. 73 | 74 | ## Attribution 75 | 76 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 77 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 78 | 79 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 80 | 81 | [homepage]: https://www.contributor-covenant.org 82 | 83 | For answers to common questions about this code of conduct, see the FAQ at 84 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 85 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guide 2 | 3 | Contributions to this project are welcome. If you have an idea for a bigger change, [open an issue first](https://github.com/brettchalupa/graphql-docs/issues/new/choose) and we can discuss it. 4 | 5 | For fixes and small additions, follow the steps below to get developing and contributing: 6 | 7 | 1. Fork & clone the repository in GitHub 8 | 2. Run the `bin/setup` script to install development dependencies 9 | 3. Work on a branch 10 | 4. Make changes 11 | 5. Ensure tests pass by running `bin/rake` 12 | 6. Commit your changes, this project follows [the Conventional Commits spec](https://www.conventionalcommits.org/en/v1.0.0/) 13 | 7. Open up a pull request 14 | 15 | ## Finding Issues 16 | 17 | - Good First Issue — If you're new to the project or Ruby, check out the ["good first issue" tag](https://github.com/brettchalupa/graphql-docs/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22). They're smaller, approachable issues if you're just getting started. 18 | - Web — tasks that don't require much Ruby knowledge but require HTML and CSS have the ["web" tag](https://github.com/brettchalupa/graphql-docs/issues?q=is%3Aopen+is%3Aissue+label%3A%22web%22+) 19 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | # Specify your gem's dependencies in graphql-docs.gemspec 6 | gemspec 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Garen Torikian 2 | Copyright (c) 2022 Brett Chalupa 3 | 4 | MIT License 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GraphQLDocs 2 | 3 | Ruby library and CLI for easily generating beautiful documentation from your GraphQL schema. 4 | 5 |  6 | 7 | ## Installation 8 | 9 | Add the gem to your project with this command: 10 | 11 | ```console 12 | bundle add graphql-docs 13 | ``` 14 | 15 | Or install it yourself as: 16 | 17 | ```console 18 | gem install graphql-docs 19 | ``` 20 | 21 | ## Usage 22 | 23 | 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: 24 | 25 | ```ruby 26 | # pass in a filename 27 | GraphQLDocs.build(filename: filename) 28 | 29 | # or pass in a string 30 | GraphQLDocs.build(schema: contents) 31 | 32 | # or a schema class 33 | schema = GraphQL::Schema.define do 34 | query query_type 35 | end 36 | GraphQLDocs.build(schema: schema) 37 | ``` 38 | 39 | GraphQLDocs also has a simplified CLI (`graphql-docs`) that gets installed with the gem: 40 | 41 | ```console 42 | graphql-docs schema.graphql 43 | ``` 44 | 45 | That will generate the output in the `output` dir. 46 | 47 | See all of the supported CLI options with: 48 | 49 | ```console 50 | graphql-docs -h 51 | ``` 52 | 53 | ## Breakdown 54 | 55 | There are several phases going on the single `GraphQLDocs.build` call: 56 | 57 | - The GraphQL IDL file is read (if you passed `filename`) through `GraphQL::Client` (or simply read if you passed a string through `schema`). 58 | - `GraphQL::Parser` manipulates the IDL into a slightly saner format. 59 | - `GraphQL::Generator` takes that saner format and begins the process of applying items to the HTML templates. 60 | - `GraphQL::Renderer` technically runs as part of the generation phase. It passes the contents of each page and converts it into HTML. 61 | 62 | If you wanted to, you could break these calls up individually. For example: 63 | 64 | ```ruby 65 | options = {} 66 | options[:filename] = "#{File.dirname(__FILE__)}/../data/graphql/schema.idl" 67 | options[:renderer] = MySuperCoolRenderer 68 | 69 | options = GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge(options) 70 | 71 | response = File.read(options[:filename]) 72 | 73 | parser = GraphQLDocs::Parser.new(response, options) 74 | parsed_schema = parser.parse 75 | 76 | generator = GraphQLDocs::Generator.new(parsed_schema, options) 77 | 78 | generator.generate 79 | ``` 80 | 81 | ## Generating output 82 | 83 | 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. 84 | 85 | It also uses [html-pipeline](https://github.com/jch/html-pipeline) to perform the rendering by default. You can override this by providing a custom rendering class.You must implement two methods: 86 | 87 | - `initialize` - Takes two arguments, the parsed `schema` and the configuration `options`. 88 | - `render` Takes the contents of a template page. It also takes two optional kwargs, the GraphQL `type` and its `name`. For example: 89 | 90 | ```ruby 91 | class CustomRenderer 92 | def initialize(parsed_schema, options) 93 | @parsed_schema = parsed_schema 94 | @options = options 95 | end 96 | 97 | def render(contents, type: nil, name: nil) 98 | contents.sub(/Repository/i, 'Meow Woof!') 99 | 100 | opts[:content] = contents 101 | @graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding }) 102 | end 103 | end 104 | 105 | options[:filename] = 'location/to/sw-api.graphql' 106 | options[:renderer] = CustomRenderer 107 | 108 | GraphQLDocs.build(options) 109 | ``` 110 | 111 | If your `render` method returns `nil`, the `Generator` will not attempt to write any HTML file. 112 | 113 | ### Templates 114 | 115 | The layouts for the individual GraphQL pages are ERB templates, but you can also use ERB templates for your static landing pages. 116 | 117 | If you want to add additional variables for your landing pages, you can add define a `variables` hash within the `landing_pages` option. 118 | 119 | ### Helper methods 120 | 121 | In your ERB layouts, there are several helper methods you can use. The helper methods are: 122 | 123 | - `slugify(str)` - This slugifies the given string. 124 | - `include(filename, opts)` - This embeds a template from your `includes` folder, passing along the local options provided. 125 | - `markdownify(string)` - This converts a string into HTML via CommonMarker. 126 | - `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. 127 | 128 | To call these methods within templates, you must use the dot notation, such as `<%= slugify.(text) %>`. 129 | 130 | ## Configuration 131 | 132 | The following options are available: 133 | 134 | | Option | Description | Default | 135 | | :------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------- | 136 | | `filename` | The location of your schema's IDL file. | `nil` | 137 | | `schema` | A string representing a schema IDL file. | `nil` | 138 | | `output_dir` | The location of the output HTML. | `./output/` | 139 | | `use_default_styles` | Indicates if you want to use the default styles. | `true` | 140 | | `base_url` | Indicates the base URL to prepend for assets and links. | `""` | 141 | | `delete_output` | Deletes `output_dir` before generating content. | `false` | 142 | | `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. | 143 | | `renderer` | The rendering class to use. | `GraphQLDocs::Renderer` | 144 | | `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/_. | 145 | | `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/_. | 146 | | `classes` | Additional class names you can provide to certain elements. | The full list is available in _lib/graphql-docs/configuration.rb_. | 147 | | `notices` | A proc used to add notices to schema members. See _Customizing Notices_ section below. | `nil` | 148 | 149 | ### Customizing Notices 150 | 151 | A notice is a block of CommonMark text that optionally has a title which is displayed above a schema member's description. The 152 | look of a notice block can be controlled by specifying a custom class for it and then styled via CSS. 153 | 154 | The `notices` option allows you to customize the notices that appear for a specific schema member using a proc. 155 | 156 | 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. 157 | 158 | A `notice` has the following options: 159 | 160 | | Option | Description | 161 | | :------------ | :-------------------------------------------------------- | 162 | | `body` | CommonMark body of the notice | 163 | | `title` | Optional title of the notice | 164 | | `class` | Optional CSS class for the wrapper `
<%= implementor %>
<%= interface %>
Argument | 5 |Type | 6 |Description | 7 |
---|---|---|
<%= argument[:name] %> |
13 |
14 | <%= argument[:type][:info] %>
15 | |
16 |
17 | <%= markdownify.(argument[:description]) %>
18 | <% unless (default_value = argument[:default_value]).nil? %>
19 | The default value is |
22 |
<%= connection[:type][:info] %>
)
5 |
6 | <%= field[:type][:info] %>
)
5 |
6 | <%= field[:type][:info] %>
)
5 |
6 | Operations
15 | 27 |
}, contents
77 | end
78 | end
79 |
80 | def test_that_turning_off_styles_works
81 | options = deep_copy(GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS)
82 | options[:output_dir] = @output_dir
83 | options[:delete_output] = true
84 | options[:use_default_styles] = false
85 |
86 | generator = GraphQLDocs::Generator.new(@tiny_results, options)
87 | generator.generate
88 |
89 | refute File.exist? File.join(@output_dir, 'assets', 'style.css')
90 | end
91 |
92 | def test_that_setting_base_url_works
93 | options = deep_copy(GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS)
94 | options[:output_dir] = @output_dir
95 | options[:delete_output] = true
96 | options[:base_url] = 'wowzers'
97 |
98 | generator = GraphQLDocs::Generator.new(@tiny_results, options)
99 | generator.generate
100 |
101 | contents = File.read File.join(@output_dir, 'index.html')
102 | assert_match %r{}, contents
103 |
104 | contents = File.read File.join(@output_dir, 'object', 'codeofconduct', 'index.html')
105 | assert_match %r{href="wowzers/object/codeofconduct/"}, contents
106 | end
107 |
108 | def test_that_custom_renderer_can_be_used
109 | options = deep_copy(GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS)
110 | options[:output_dir] = @output_dir
111 |
112 | options[:renderer] = CustomRenderer
113 |
114 | generator = GraphQLDocs::Generator.new(@tiny_results, options)
115 | generator.generate
116 |
117 | contents = File.read(File.join(@output_dir, 'object', 'codeofconduct', 'index.html'))
118 |
119 | assert_match(/CoC!!!!!/, contents)
120 | end
121 |
122 | def test_that_it_sets_classes
123 | options = deep_copy(GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS)
124 | options[:output_dir] = @output_dir
125 | options[:delete_output] = true
126 | options[:classes][:field_entry] = 'my-4'
127 |
128 | generator = GraphQLDocs::Generator.new(@tiny_results, options)
129 | generator.generate
130 |
131 | object = File.read File.join(@output_dir, 'object', 'codeofconduct', 'index.html')
132 |
133 | assert_match(/The code of conduct's key
}, contents) 193 | end 194 | 195 | def test_that_non_empty_html_lines_not_interpreted_by_markdown 196 | options = deep_copy(GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS) 197 | options[:output_dir] = @output_dir 198 | 199 | generator = GraphQLDocs::Generator.new(@results, options) 200 | generator.generate 201 | 202 | contents = File.read File.join(@output_dir, 'input_object', 'projectorder', 'index.html') 203 | 204 | assert_match %r{The direction in which to order projects by the specified field.
\s+R2D2
', contents 22 | end 23 | 24 | def test_that_unsafe_html_is_not_blocked_by_default 25 | contents = @renderer.to_html('Oh hello') 26 | 27 | assert_equal 'Oh hello
', contents 28 | end 29 | 30 | def test_that_unsafe_html_is_blocked_when_asked 31 | renderer = GraphQLDocs::Renderer.new(@parsed_schema, GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge({ 32 | pipeline_config: { 33 | pipeline: 34 | %i[ExtendedMarkdownFilter 35 | EmojiFilter 36 | TableOfContentsFilter], 37 | context: { 38 | gfm: false, 39 | unsafe: false, 40 | asset_root: 'https://a248.e.akamai.net/assets.github.com/images/icons' 41 | } 42 | } 43 | })) 44 | contents = renderer.to_html('Oh **hello**') 45 | 46 | assert_equal 'Oh hello
', contents 47 | end 48 | 49 | def test_that_filename_accessible_to_filters 50 | renderer = GraphQLDocs::Renderer.new(@parsed_schema, GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge({ 51 | pipeline_config: { 52 | pipeline: 53 | %i[ExtendedMarkdownFilter 54 | EmojiFilter 55 | TableOfContentsFilter 56 | AddFilenameFilter], 57 | context: { 58 | gfm: false, 59 | unsafe: true, 60 | asset_root: 'https://a248.e.akamai.net/assets.github.com/images/icons' 61 | } 62 | } 63 | })) 64 | contents = renderer.render('', type: 'Droid', name: 'R2D2', filename: '/this/is/the/filename') 65 | assert_match %r{/this/is/the/filename}, contents 66 | end 67 | end 68 | 69 | class AddFilenameFilter < HTML::Pipeline::Filter 70 | def call 71 | doc.search('span[@id="fill-me"]').each do |span| 72 | span.inner_html = context[:filename] 73 | end 74 | doc 75 | end 76 | 77 | def validate 78 | needs :filename 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.unshift File.expand_path('../lib', __dir__) 4 | require 'graphql-docs' 5 | 6 | require 'minitest/autorun' 7 | require 'minitest/pride' 8 | require 'minitest/focus' 9 | 10 | def fixtures_dir 11 | File.join(File.dirname(__FILE__), 'graphql-docs', 'fixtures') 12 | end 13 | 14 | def output_dir 15 | File.join(fixtures_dir, 'output') 16 | end 17 | def clean_up_output 18 | FileUtils.rm_rf(output_dir) 19 | end 20 | clean_up_output 21 | 22 | class QueryType < GraphQL::Schema::Object 23 | field :my_field, Int, "Title paragraph. 24 | ``` 25 | line1 26 | line2 27 | line3 28 | ```", null: false 29 | 30 | field :deprecated_field, Int, deprecation_reason: "Not useful any more" 31 | 32 | field :field_with_deprecated_arg, Int do 33 | argument :my_arg, Int, required: false, deprecation_reason: "Not useful any more" 34 | end 35 | end 36 | 37 | class MySchema < GraphQL::Schema 38 | query QueryType 39 | end 40 | --------------------------------------------------------------------------------