Skip to content

Commit fdc62e4

Browse files
authored
Merge pull request #19 from gjtorikian/query-is-root
Set query as a top-level item
2 parents cccc09e + bd43bfa commit fdc62e4

29 files changed

+269
-36
lines changed

.travis.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
language: ruby
22
rvm:
3-
- 2.3.1
3+
- 2.3.4
4+
- 2.4.0
5+
6+
git:
7+
depth: 10
8+
9+
env:
10+
global:
11+
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
412

513
sudo: false
614
cache: bundler
715

8-
git:
9-
depth: 10
16+
addons:
17+
apt:
18+
sources:
19+
- kalakris-cmake
20+
packages:
21+
- cmake
22+
23+
matrix:
24+
include:
25+
- script: bundle exec rake rubocop
26+
rvm: 2.4.0

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ The following options are available:
134134
| `delete_output` | Deletes `output_dir` before generating content. | `false` |
135135
| `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. |
136136
| `renderer` | The rendering class to use. | `GraphQLDocs::Renderer`
137-
| `templates` | The templates to use when generating HTML. You may override any of the following keys: `includes`, `objects`, `mutations`, `interfaces`, `enums`, `unions`, `input_objects`, `scalars`, `index`. | The defaults are found in _lib/graphql-docs/layouts/_.
137+
| `templates` | The templates to use when generating HTML. You may override any of the following keys: `default`, `includes`, `objects`, `mutations`, `interfaces`, `enums`, `unions`, `input_objects`, `scalars`. | The defaults are found in _lib/graphql-docs/layouts/_.
138+
| `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`. | The defaults are found in _lib/graphql-docs/layouts/_.
138139
| `classes` | Additional class names you can provide to certain elements. | The full list is found in _lib/graphql-docs/configuration.rb/_.
139140

140141
## Development

Rakefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
require 'bundler/gem_tasks'
22
require 'rake/testtask'
33

4+
require 'rubocop/rake_task'
5+
6+
RuboCop::RakeTask.new(:rubocop)
7+
48
Rake::TestTask.new(:test) do |t|
59
t.libs << 'test'
610
t.libs << 'lib'
@@ -33,7 +37,7 @@ task :generate_sample, [:base_url] do |task, args|
3337
GraphQLDocs.build(options)
3438
end
3539

36-
task :sample => [:generate_sample] do
40+
task sample: [:generate_sample] do
3741
require 'webrick'
3842

3943
puts 'Navigate to http://localhost:3000 to see the sample docs'

lib/graphql-docs.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# rubocop:disable Style/FileName
12
require 'graphql-docs/client'
23
require 'graphql-docs/helpers'
34
require 'graphql-docs/renderer'

lib/graphql-docs/configuration.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@ module Configuration
3636
unions: "#{File.dirname(__FILE__)}/layouts/graphql_unions.html",
3737
input_objects: "#{File.dirname(__FILE__)}/layouts/graphql_input_objects.html",
3838
scalars: "#{File.dirname(__FILE__)}/layouts/graphql_scalars.html",
39+
},
3940

40-
index: "#{File.dirname(__FILE__)}/layouts/index.md",
41+
landing_pages: {
42+
index: "#{File.dirname(__FILE__)}/landing_pages/index.md",
43+
query: "#{File.dirname(__FILE__)}/landing_pages/query.md",
44+
object: "#{File.dirname(__FILE__)}/landing_pages/object.md",
45+
mutation: "#{File.dirname(__FILE__)}/landing_pages/mutation.md",
46+
interface: "#{File.dirname(__FILE__)}/landing_pages/interface.md",
47+
enum: "#{File.dirname(__FILE__)}/landing_pages/enum.md",
48+
union: "#{File.dirname(__FILE__)}/landing_pages/union.md",
49+
input_object: "#{File.dirname(__FILE__)}/landing_pages/input_object.md",
50+
scalar: "#{File.dirname(__FILE__)}/landing_pages/scalar.md"
4151
},
4252

4353
classes: {

lib/graphql-docs/generator.rb

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,36 @@ def generate
3333
create_graphql_input_object_pages
3434
create_graphql_scalar_pages
3535

36-
unless @options[:templates][:index].nil?
37-
write_file('static', 'index', File.read(@options[:templates][:index]))
36+
unless @options[:landing_pages][:index].nil?
37+
write_file('static', 'index', File.read(@options[:landing_pages][:index]))
38+
end
39+
40+
unless @options[:landing_pages][:object].nil?
41+
write_file('static', 'object', File.read(@options[:landing_pages][:object]))
42+
end
43+
44+
unless @options[:landing_pages][:mutation].nil?
45+
write_file('static', 'mutation', File.read(@options[:landing_pages][:mutation]))
46+
end
47+
48+
unless @options[:landing_pages][:interface].nil?
49+
write_file('static', 'interface', File.read(@options[:landing_pages][:interface]))
50+
end
51+
52+
unless @options[:landing_pages][:enum].nil?
53+
write_file('static', 'enum', File.read(@options[:landing_pages][:enum]))
54+
end
55+
56+
unless @options[:landing_pages][:union].nil?
57+
write_file('static', 'union', File.read(@options[:landing_pages][:union]))
58+
end
59+
60+
unless @options[:landing_pages][:input_object].nil?
61+
write_file('static', 'input_object', File.read(@options[:landing_pages][:input_object]))
62+
end
63+
64+
unless @options[:landing_pages][:scalar].nil?
65+
write_file('static', 'scalar', File.read(@options[:landing_pages][:scalar]))
3866
end
3967

4068
if @options[:use_default_styles]
@@ -54,9 +82,32 @@ def generate
5482
def create_graphql_object_pages
5583
graphql_object_types.each do |object_type|
5684
next if object_type['name'].start_with?('__')
57-
opts = default_generator_options(type: object_type)
58-
contents = @graphql_object_template.result(OpenStruct.new(opts).instance_eval { binding })
59-
write_file('object', object_type['name'], contents)
85+
if object_type['name'] == 'Mutation'
86+
next unless @options[:landing_pages][:mutation].nil?
87+
end
88+
if object_type['name'] == 'Query'
89+
metadata = ''
90+
unless @options[:landing_pages][:query].nil?
91+
query_landing_page = @options[:landing_pages][:query]
92+
query_landing_page = File.read(query_landing_page)
93+
if @renderer.respond_to?(:has_yaml?) && \
94+
@renderer.has_yaml?(query_landing_page) && \
95+
@renderer.respond_to?(:yaml_split)
96+
pieces = @renderer.yaml_split(query_landing_page)
97+
pieces[2] = pieces[2].chomp
98+
metadata = pieces[1, 3].join("\n")
99+
query_landing_page = pieces[4]
100+
end
101+
object_type['description'] = query_landing_page
102+
end
103+
opts = default_generator_options(type: object_type)
104+
contents = @graphql_object_template.result(OpenStruct.new(opts).instance_eval { binding })
105+
write_file('static', 'query', metadata + contents)
106+
else
107+
opts = default_generator_options(type: object_type)
108+
contents = @graphql_object_template.result(OpenStruct.new(opts).instance_eval { binding })
109+
write_file('object', object_type['name'], contents)
110+
end
60111
end
61112
end
62113

@@ -131,6 +182,7 @@ def write_file(type, name, contents)
131182
path = @options[:output_dir]
132183
else
133184
path = File.join(@options[:output_dir], name)
185+
FileUtils.mkdir_p(path)
134186
end
135187
else
136188
path = File.join(@options[:output_dir], type, name.downcase)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Enums
3+
---
4+
5+
# Enums
6+
7+
Enums represent a possible set of values for a field. For example, the `Issue` object has a field called `state`. The state of an issue may be `OPEN` or `CLOSED`.
8+
9+
For more information, see [the GraphQL spec](https://facebook.github.io/graphql/#sec-Enums).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
title: GraphQL documentation
3+
---
4+
15
# GraphQL Reference
26

37
These docs were generated by [graphql-docs](https://github.com/gjtorikian/graphql-docs).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Input Objects
3+
---
4+
5+
# Input Objects
6+
7+
Input objects are best described as "composable objects" in that they contain a set of input fields that define a particular object. For example, the `AuthorInput` takes a field called `emails`. Providing a value for `emails` will transform the `AuthorInput` into a list of `User` objects which contain that email address/
8+
9+
For more information, see [the GraphQL spec](https://facebook.github.io/graphql/#sec-Input-Objects).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Interfaces
3+
---
4+
5+
# Interfaces
6+
7+
GraphQL Interfaces are a sort of "parent object" from which other objects can "inherit" from. For example, `Stars` is considered an interface, because both `Repository` and `Gist` can be starred. An interface has its own list of named fields that are shared by implementing objects.
8+
9+
For more information, see [the GraphQL spec](https://facebook.github.io/graphql/#sec-Interfaces).

0 commit comments

Comments
 (0)