diff --git a/lib/graphql-docs/configuration.rb b/lib/graphql-docs/configuration.rb index e044197..f1f8c5d 100644 --- a/lib/graphql-docs/configuration.rb +++ b/lib/graphql-docs/configuration.rb @@ -32,6 +32,7 @@ module Configuration operations: "#{File.dirname(__FILE__)}/layouts/graphql_operations.html", objects: "#{File.dirname(__FILE__)}/layouts/graphql_objects.html", + queries: "#{File.dirname(__FILE__)}/layouts/graphql_queries.html", mutations: "#{File.dirname(__FILE__)}/layouts/graphql_mutations.html", interfaces: "#{File.dirname(__FILE__)}/layouts/graphql_interfaces.html", enums: "#{File.dirname(__FILE__)}/layouts/graphql_enums.html", diff --git a/lib/graphql-docs/generator.rb b/lib/graphql-docs/generator.rb index c7b6aa7..2451c43 100644 --- a/lib/graphql-docs/generator.rb +++ b/lib/graphql-docs/generator.rb @@ -17,7 +17,7 @@ def initialize(parsed_schema, options) @renderer = @options[:renderer].new(@parsed_schema, @options) - %i[operations objects mutations interfaces enums unions input_objects scalars directives].each do |sym| + %i[operations objects queries mutations interfaces enums unions input_objects scalars directives].each do |sym| raise IOError, "`#{sym}` template #{@options[:templates][sym]} was not found" unless File.exist?(@options[:templates][sym]) instance_variable_set("@graphql_#{sym}_template", ERB.new(File.read(@options[:templates][sym]))) @@ -52,8 +52,9 @@ def initialize(parsed_schema, options) def generate FileUtils.rm_rf(@options[:output_dir]) if @options[:delete_output] - has_query = create_graphql_query_pages + has_query = create_graphql_operation_pages create_graphql_object_pages + create_graphql_query_pages create_graphql_mutation_pages create_graphql_interface_pages create_graphql_enum_pages @@ -96,7 +97,7 @@ def generate true end - def create_graphql_query_pages + def create_graphql_operation_pages graphql_operation_types.each do |query_type| metadata = '' next unless query_type[:name] == graphql_root_types['query'] @@ -129,6 +130,15 @@ def create_graphql_object_pages end end + def create_graphql_query_pages + graphql_query_types.each do |query| + opts = default_generator_options(type: query) + + contents = @graphql_queries_template.result(OpenStruct.new(opts).instance_eval { binding }) + write_file('query', query[:name], contents) + end + end + def create_graphql_mutation_pages graphql_mutation_types.each do |mutation| opts = default_generator_options(type: mutation) diff --git a/lib/graphql-docs/helpers.rb b/lib/graphql-docs/helpers.rb index 1471956..10f16d8 100644 --- a/lib/graphql-docs/helpers.rb +++ b/lib/graphql-docs/helpers.rb @@ -36,6 +36,10 @@ def graphql_operation_types @parsed_schema[:operation_types] || [] end + def graphql_query_types + @parsed_schema[:query_types] || [] + end + def graphql_mutation_types @parsed_schema[:mutation_types] || [] end diff --git a/lib/graphql-docs/landing_pages/query.md b/lib/graphql-docs/landing_pages/query.md index 67ce0db..2c2f051 100644 --- a/lib/graphql-docs/landing_pages/query.md +++ b/lib/graphql-docs/landing_pages/query.md @@ -1,4 +1,8 @@ --- title: Queries --- -Every GraphQL schema has a root type for both queries and mutations. The [query type](http://spec.graphql.org/draft/#sec-Type-System) defines GraphQL operations that retrieve data from the server. +Every GraphQL schema has a root type for both queries and mutations. + +The query type defines GraphQL operations that retrieve data from the server. + +For more information, see [the GraphQL spec](http://spec.graphql.org/draft/#sec-Type-System). diff --git a/lib/graphql-docs/layouts/graphql_operations.html b/lib/graphql-docs/layouts/graphql_operations.html index c8824ab..ac38a95 100644 --- a/lib/graphql-docs/layouts/graphql_operations.html +++ b/lib/graphql-docs/layouts/graphql_operations.html @@ -1,19 +1,3 @@

<%= type[:name] %>

<%= type[:description] %> - -<% unless type[:connections].empty? %> - -

Connections

- -<%= include.('connections.html', connections: type[:connections]) %> - -<% end %> - -<% unless type[:fields].empty? %> - -

Fields

- -<%= include.('fields.html', fields: type[:fields]) %> - -<% end %> diff --git a/lib/graphql-docs/layouts/graphql_queries.html b/lib/graphql-docs/layouts/graphql_queries.html new file mode 100644 index 0000000..fbe0cec --- /dev/null +++ b/lib/graphql-docs/layouts/graphql_queries.html @@ -0,0 +1,22 @@ +

<%= type[:name] %>

+ +<%= include.('notices.html', notices: type[:notices]) %> + +<%= type[:description] %> + +<% if !type[:arguments].empty? %> + +

Arguments

+ +<%= include.('fields.html', fields: type[:arguments]) %> + +<% end %> + + +<% if !type[:return_fields].empty? %> + +

Return fields

+ +<%= include.('fields.html', fields: type[:return_fields]) %> + +<% end %> diff --git a/lib/graphql-docs/layouts/includes/sidebar.html b/lib/graphql-docs/layouts/includes/sidebar.html index dff27ed..23d6780 100644 --- a/lib/graphql-docs/layouts/includes/sidebar.html +++ b/lib/graphql-docs/layouts/includes/sidebar.html @@ -7,7 +7,7 @@
  • -

    Queries

    +

    Operations