From 27cb57e3b5395fef241d54f271eb71177d966cf2 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 24 Oct 2017 23:23:36 -0400 Subject: [PATCH 01/20] Bootstrap GraphQL api extension --- .../refinery/api/graphql_controller.rb | 19 ++++ api/config/routes.rb | 9 ++ api/lib/generators/refinery/api_generator.rb | 19 ++++ api/lib/refinery/api.rb | 23 +++++ api/lib/refinery/api/engine.rb | 23 +++++ api/lib/refinerycms-api.rb | 1 + api/license.md | 21 ++++ api/refinerycms-api.gemspec | 36 +++++++ .../features/refinery/apis/admin/apis_spec.rb | 98 +++++++++++++++++++ api/spec/models/refinery/apis/api_spec.rb | 18 ++++ api/spec/spec_helper.rb | 30 ++++++ api/spec/support/factories/refinery/apis.rb | 7 ++ 12 files changed, 304 insertions(+) create mode 100644 api/app/controllers/refinery/api/graphql_controller.rb create mode 100644 api/config/routes.rb create mode 100644 api/lib/generators/refinery/api_generator.rb create mode 100644 api/lib/refinery/api.rb create mode 100644 api/lib/refinery/api/engine.rb create mode 100644 api/lib/refinerycms-api.rb create mode 100644 api/license.md create mode 100644 api/refinerycms-api.gemspec create mode 100644 api/spec/features/refinery/apis/admin/apis_spec.rb create mode 100644 api/spec/models/refinery/apis/api_spec.rb create mode 100644 api/spec/spec_helper.rb create mode 100644 api/spec/support/factories/refinery/apis.rb diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb new file mode 100644 index 0000000000..1e8b9ba7ab --- /dev/null +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -0,0 +1,19 @@ +module Refinery + module Api + class GraphqlController < ::ApplicationController + + def execute + query = params[:query] + variables = params[:variables] || {} + context = { + current_user: current_user + } + begin + result = GraphqlSchema.execute(query, variables: variables, context: context) + rescue => error + result = { errors: [{ message: error.message }] } + end + render json: result + end + end +end diff --git a/api/config/routes.rb b/api/config/routes.rb new file mode 100644 index 0000000000..bbb6727a7d --- /dev/null +++ b/api/config/routes.rb @@ -0,0 +1,9 @@ +Refinery::Core::Engine.routes.draw do + namespace :api do + post 'graphql' => 'graphql#execute' + + if Rails.env.development? + mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql" + end + end +end diff --git a/api/lib/generators/refinery/api_generator.rb b/api/lib/generators/refinery/api_generator.rb new file mode 100644 index 0000000000..d9e04600b2 --- /dev/null +++ b/api/lib/generators/refinery/api_generator.rb @@ -0,0 +1,19 @@ +module Refinery + class ApiGenerator < Rails::Generators::Base + + def rake_db + rake "refinery_api:install:migrations" + end + + def append_load_seed_data + create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb')) + append_file 'db/seeds.rb', :verbose => true do + <<-EOH + +# Added by Refinery CMS Apis extension +Refinery::Api::Engine.load_seed + EOH + end + end + end +end diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb new file mode 100644 index 0000000000..9333150cb8 --- /dev/null +++ b/api/lib/refinery/api.rb @@ -0,0 +1,23 @@ +require 'refinerycms-core' +require 'graphql' +require 'graphiql-rails' + +module Refinery + autoload :ApiGenerator, 'generators/refinery/api_generator' + + module Api + require 'refinery/api/engine' + + class << self + attr_writer :root + + def root + @root ||= Pathname.new(File.expand_path('../../../', __FILE__)) + end + + def factory_paths + @factory_paths ||= [ root.join('spec', 'factories').to_s ] + end + end + end +end diff --git a/api/lib/refinery/api/engine.rb b/api/lib/refinery/api/engine.rb new file mode 100644 index 0000000000..0c042584f9 --- /dev/null +++ b/api/lib/refinery/api/engine.rb @@ -0,0 +1,23 @@ +module Refinery + module Api + class Engine < Rails::Engine + extend Refinery::Engine + isolate_namespace Refinery::Api + + engine_name :refinery_api + + before_inclusion do + Refinery::Plugin.register do |plugin| + plugin.name = "api" + plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.api_admin_apis_path } + plugin.pathname = root + + end + end + + config.after_initialize do + Refinery.register_extension(Refinery::Api) + end + end + end +end diff --git a/api/lib/refinerycms-api.rb b/api/lib/refinerycms-api.rb new file mode 100644 index 0000000000..c8f56017b7 --- /dev/null +++ b/api/lib/refinerycms-api.rb @@ -0,0 +1 @@ +require 'refinery/api' diff --git a/api/license.md b/api/license.md new file mode 100644 index 0000000000..a2792fd6c8 --- /dev/null +++ b/api/license.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2017 [Brice Sanchez](http://brice-sanchez.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec new file mode 100644 index 0000000000..75cc54e24c --- /dev/null +++ b/api/refinerycms-api.gemspec @@ -0,0 +1,36 @@ +# Encoding: UTF-8 +require File.expand_path('../../core/lib/refinery/version', __FILE__) + +version = Refinery::Version.to_s + +Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = %q{refinerycms-api} + s.version = version + s.summary = %q{Api extension for Refinery CMS} + s.description = %q{Api extension for Refinery CMS} + s.email = %q{} + s.homepage = %q{http://refinerycms.com} + s.rubyforge_project = %q{refinerycms} + s.authors = ['Brice Sanchez'] + s.license = %q{MIT} + s.require_paths = %w(lib) + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- spec/*`.split("\n") + + # Runtime dependencies + s.add_dependency 'refinerycms-core', '~> 4.0.0' + s.add_dependency 'graphql', '~> 1.7' + s.add_dependency 'graphiql-rails', '~> 1.4' + + # Development dependencies (usually used for testing) + s.add_development_dependency 'refinerycms-testing', '~> 4.0.0' + + s.required_ruby_version = Refinery::Version.required_ruby_version + + s.cert_chain = [File.expand_path("../../certs/parndt.pem", __FILE__)] + if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__) + s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") + end +end \ No newline at end of file diff --git a/api/spec/features/refinery/apis/admin/apis_spec.rb b/api/spec/features/refinery/apis/admin/apis_spec.rb new file mode 100644 index 0000000000..569b57d537 --- /dev/null +++ b/api/spec/features/refinery/apis/admin/apis_spec.rb @@ -0,0 +1,98 @@ +# encoding: utf-8 +require "spec_helper" + +describe Refinery do + describe "Apis" do + describe "Admin" do + describe "api", type: :feature do + refinery_login + + describe "api list" do + before do + FactoryGirl.create(:api, :title => "UniqueTitleOne") + FactoryGirl.create(:api, :title => "UniqueTitleTwo") + end + + it "shows two items" do + visit refinery.apis_admin_apis_path + expect(page).to have_content("UniqueTitleOne") + expect(page).to have_content("UniqueTitleTwo") + end + end + + describe "create" do + before do + visit refinery.apis_admin_apis_path + + click_link "Add New Api" + end + + context "valid data" do + it "should succeed" do + fill_in "Title", :with => "This is a test of the first string field" + expect { click_button "Save" }.to change(Refinery::Apis::Api, :count).from(0).to(1) + + expect(page).to have_content("'This is a test of the first string field' was successfully added.") + end + end + + context "invalid data" do + it "should fail" do + expect { click_button "Save" }.not_to change(Refinery::Apis::Api, :count) + + expect(page).to have_content("Title can't be blank") + end + end + + context "duplicate" do + before { FactoryGirl.create(:api, :title => "UniqueTitle") } + + it "should fail" do + visit refinery.apis_admin_apis_path + + click_link "Add New Api" + + fill_in "Title", :with => "UniqueTitle" + expect { click_button "Save" }.not_to change(Refinery::Apis::Api, :count) + + expect(page).to have_content("There were problems") + end + end + + end + + describe "edit" do + before { FactoryGirl.create(:api, :title => "A title") } + + it "should succeed" do + visit refinery.apis_admin_apis_path + + within ".actions" do + click_link "Edit this api" + end + + fill_in "Title", :with => "A different title" + click_button "Save" + + expect(page).to have_content("'A different title' was successfully updated.") + expect(page).not_to have_content("A title") + end + end + + describe "destroy" do + before { FactoryGirl.create(:api, :title => "UniqueTitleOne") } + + it "should succeed" do + visit refinery.apis_admin_apis_path + + click_link "Remove this api forever" + + expect(page).to have_content("'UniqueTitleOne' was successfully removed.") + expect(Refinery::Apis::Api.count).to eq(0) + end + end + + end + end + end +end diff --git a/api/spec/models/refinery/apis/api_spec.rb b/api/spec/models/refinery/apis/api_spec.rb new file mode 100644 index 0000000000..2192ed77b4 --- /dev/null +++ b/api/spec/models/refinery/apis/api_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +module Refinery + module Apis + describe Api do + describe "validations", type: :model do + subject do + FactoryGirl.create(:api, + :title => "Refinery CMS") + end + + it { should be_valid } + its(:errors) { should be_empty } + its(:title) { should == "Refinery CMS" } + end + end + end +end diff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rb new file mode 100644 index 0000000000..ecf8a46790 --- /dev/null +++ b/api/spec/spec_helper.rb @@ -0,0 +1,30 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] ||= 'test' + +if File.exist?(dummy_path = File.expand_path('../dummy/config/environment.rb', __FILE__)) + require dummy_path +elsif File.dirname(__FILE__) =~ %r{vendor/extensions} + # Require the path to the refinerycms application this is vendored inside. + require File.expand_path('../../../../../config/environment', __FILE__) +else + puts "Could not find a config/environment.rb file to require. Please specify this in #{File.expand_path(__FILE__)}" +end + +require 'rspec/rails' +require 'capybara/rspec' + +Rails.backtrace_cleaner.remove_silencers! + +RSpec.configure do |config| + config.mock_with :rspec + config.filter_run :focus => true + config.run_all_when_everything_filtered = true +end + +# Requires supporting files with custom matchers and macros, etc, +# in ./support/ and its subdirectories including factories. +([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{ |p| + Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s] +}.flatten.sort.each do |support_file| + require support_file +end diff --git a/api/spec/support/factories/refinery/apis.rb b/api/spec/support/factories/refinery/apis.rb new file mode 100644 index 0000000000..be32c4e82d --- /dev/null +++ b/api/spec/support/factories/refinery/apis.rb @@ -0,0 +1,7 @@ + +FactoryGirl.define do + factory :api, :class => Refinery::Apis::Api do + sequence(:title) { |n| "refinery#{n}" } + end +end + From 5116a4ff121d8f37ca7a5d8b1e753fee1d95274d Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 24 Oct 2017 23:24:00 -0400 Subject: [PATCH 02/20] Register it to refinerycms main app --- Gemfile | 1 + lib/refinery/all.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b1195b6209..0c316ab117 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ path "./" do gem "refinerycms-images" gem "refinerycms-pages" gem "refinerycms-resources" + gem "refinerycms-api" end gem 'spring' diff --git a/lib/refinery/all.rb b/lib/refinery/all.rb index 721cd018de..5a7f0fd298 100644 --- a/lib/refinery/all.rb +++ b/lib/refinery/all.rb @@ -1,3 +1,3 @@ -%w(core images resources pages).each do |extension| +%w(core images resources pages api).each do |extension| require "refinerycms-#{extension}" end From d48bd82d01ba76483819dd48cd8f9055a74c8289 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 24 Oct 2017 23:45:26 -0400 Subject: [PATCH 03/20] Fix to be able to start the app --- api/app/controllers/refinery/api/graphql_controller.rb | 2 +- api/config/routes.rb | 2 +- api/lib/refinery/api.rb | 2 +- api/lib/refinery/api/engine.rb | 5 ++--- api/refinerycms-api.gemspec | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb index 1e8b9ba7ab..55a480ab67 100644 --- a/api/app/controllers/refinery/api/graphql_controller.rb +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -6,7 +6,7 @@ def execute query = params[:query] variables = params[:variables] || {} context = { - current_user: current_user + current_user: current_refinery_user } begin result = GraphqlSchema.execute(query, variables: variables, context: context) diff --git a/api/config/routes.rb b/api/config/routes.rb index bbb6727a7d..30469b118f 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -3,7 +3,7 @@ post 'graphql' => 'graphql#execute' if Rails.env.development? - mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql" + mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/api/graphql" end end end diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb index 9333150cb8..682f91f60e 100644 --- a/api/lib/refinery/api.rb +++ b/api/lib/refinery/api.rb @@ -1,6 +1,6 @@ require 'refinerycms-core' require 'graphql' -require 'graphiql-rails' +require 'graphiql/rails' module Refinery autoload :ApiGenerator, 'generators/refinery/api_generator' diff --git a/api/lib/refinery/api/engine.rb b/api/lib/refinery/api/engine.rb index 0c042584f9..14ea3555d0 100644 --- a/api/lib/refinery/api/engine.rb +++ b/api/lib/refinery/api/engine.rb @@ -8,10 +8,9 @@ class Engine < Rails::Engine before_inclusion do Refinery::Plugin.register do |plugin| - plugin.name = "api" - plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.api_admin_apis_path } + plugin.name = "refinerycms_api" + plugin.hide_from_menu = true plugin.pathname = root - end end diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec index 75cc54e24c..4fda0df90e 100644 --- a/api/refinerycms-api.gemspec +++ b/api/refinerycms-api.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- spec/*`.split("\n") # Runtime dependencies - s.add_dependency 'refinerycms-core', '~> 4.0.0' + s.add_dependency 'refinerycms-core', version s.add_dependency 'graphql', '~> 1.7' s.add_dependency 'graphiql-rails', '~> 1.4' From f602cbe52f811c365f3122203eb5e536b8de4b64 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Oct 2017 00:25:49 -0400 Subject: [PATCH 04/20] Add PoC to find a page by id --- .../refinery/api/graphql_controller.rb | 28 +++++++++++-------- .../graph/refinery/api/fields/page_field.rb | 19 +++++++++++++ api/app/graph/refinery/api/graphql_schema.rb | 15 ++++++++++ .../api/types/active_record_interface.rb | 26 +++++++++++++++++ api/app/graph/refinery/api/types/date_type.rb | 24 ++++++++++++++++ api/app/graph/refinery/api/types/page_type.rb | 16 +++++++++++ .../graph/refinery/api/types/query_type.rb | 15 ++++++++++ 7 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 api/app/graph/refinery/api/fields/page_field.rb create mode 100644 api/app/graph/refinery/api/graphql_schema.rb create mode 100644 api/app/graph/refinery/api/types/active_record_interface.rb create mode 100644 api/app/graph/refinery/api/types/date_type.rb create mode 100644 api/app/graph/refinery/api/types/page_type.rb create mode 100644 api/app/graph/refinery/api/types/query_type.rb diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb index 55a480ab67..251dec00c7 100644 --- a/api/app/controllers/refinery/api/graphql_controller.rb +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -2,18 +2,22 @@ module Refinery module Api class GraphqlController < ::ApplicationController - def execute - query = params[:query] - variables = params[:variables] || {} - context = { - current_user: current_refinery_user - } - begin - result = GraphqlSchema.execute(query, variables: variables, context: context) - rescue => error - result = { errors: [{ message: error.message }] } + def execute + query = params[:query] + variables = params[:variables] || {} + + context = { + current_user: current_refinery_user + } + + begin + result = Refinery::Api::GraphqlSchema.execute(query, variables: variables, context: context) + rescue => error + result = { errors: [{ message: error.message }] } + end + + render json: result end - render json: result end end -end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/fields/page_field.rb b/api/app/graph/refinery/api/fields/page_field.rb new file mode 100644 index 0000000000..33b6b8eb95 --- /dev/null +++ b/api/app/graph/refinery/api/fields/page_field.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Fields + PageField = GraphQL::Field.define do + name 'Page' + description 'Find a page by ID' + + type Types::PageType + argument :id, !types.ID + + resolve -> (obj, args, ctx) { + Refinery::Page.find_by_id(args[:id]) + } + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb new file mode 100644 index 0000000000..78f91112e2 --- /dev/null +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Refinery + module Api + GraphqlSchema = GraphQL::Schema.define do + query Types::QueryType + # mutation Types::MutationType + + resolve_type -> (obj, args, ctx) { + type_name = obj.class.name + Schema.types[type_name] + } + end + end +end diff --git a/api/app/graph/refinery/api/types/active_record_interface.rb b/api/app/graph/refinery/api/types/active_record_interface.rb new file mode 100644 index 0000000000..508e44b904 --- /dev/null +++ b/api/app/graph/refinery/api/types/active_record_interface.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + ActiveRecordInterface = GraphQL::InterfaceType.define do + name "ActiveRecord" + description "Active Record Interface" + + field :id, !types.ID + field :updated_at do + type Types::DateType + resolve -> (obj, args, ctx) { + obj.updated_at + } + end + field :created_at do + type Types::DateType + resolve -> (obj, args, ctx) { + obj.created_at + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/date_type.rb b/api/app/graph/refinery/api/types/date_type.rb new file mode 100644 index 0000000000..ec22f6ba21 --- /dev/null +++ b/api/app/graph/refinery/api/types/date_type.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + DateType = GraphQL::ScalarType.define do + name "Date" + description "Valid date format (parsable by Ruby's Date.parse)" + + coerce_input -> (value, context) do + begin Date.parse(value) + value.to_datetime + rescue ArgumentError => error + context.errors << error.message + end + end + + coerce_result -> (value, context) do + value.to_datetime + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/page_type.rb b/api/app/graph/refinery/api/types/page_type.rb new file mode 100644 index 0000000000..83a3dba1c4 --- /dev/null +++ b/api/app/graph/refinery/api/types/page_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + PageType = GraphQL::ObjectType.define do + name "Page" + description "A Page" + + interfaces [Types::ActiveRecordInterface] + + field :title, types.String + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/query_type.rb b/api/app/graph/refinery/api/types/query_type.rb new file mode 100644 index 0000000000..d915e598f1 --- /dev/null +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + QueryType = GraphQL::ObjectType.define do + name 'Query' + description 'The query root of this schema' + + field :page, field: Fields::PageField + # field :pages, field: Refinery::Api::Fields::PagesField + end + end + end +end \ No newline at end of file From 88e4743e10190da1c1d711a9a36638934fcc01b8 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 26 Oct 2017 22:47:37 -0400 Subject: [PATCH 05/20] Improve Page and PagePart ObjectType --- .../refinery/api/types/page_part_type.rb | 21 +++++++++++++++++ api/app/graph/refinery/api/types/page_type.rb | 23 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 api/app/graph/refinery/api/types/page_part_type.rb diff --git a/api/app/graph/refinery/api/types/page_part_type.rb b/api/app/graph/refinery/api/types/page_part_type.rb new file mode 100644 index 0000000000..6abe259214 --- /dev/null +++ b/api/app/graph/refinery/api/types/page_part_type.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + PagePartType = GraphQL::ObjectType.define do + name "PagePart" + description "A PagePart" + + interfaces [Types::ActiveRecordInterface] + + field :slug, types.String + field :position, types.Int + field :title, types.String + + field :locale, types.String + field :body, types.String + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/page_type.rb b/api/app/graph/refinery/api/types/page_type.rb index 83a3dba1c4..dc152b2e5d 100644 --- a/api/app/graph/refinery/api/types/page_type.rb +++ b/api/app/graph/refinery/api/types/page_type.rb @@ -9,7 +9,30 @@ module Types interfaces [Types::ActiveRecordInterface] + field :parent_id, types.Int + field :path, types.String + field :show_in_menu, types.Boolean + field :link_url, types.String + field :menu_match, types.String + field :deletable, types.Boolean + field :draft, types.Boolean + field :skip_to_first_child, types.Boolean + field :lft, types.Int + field :rgt, types.Int + field :depth, types.Int + field :view_template, types.String + field :layout_template, types.String + + field :locale, types.String field :title, types.String + field :custom_slug, types.String + field :menu_title, types.String + field :slug, types.String + + field :meta_description, types.String + field :browser_title, types.String + + field :parts, types[Types::PagePartType] end end end From 603fc692fec2fd9df2a8b6de5735d646c70c6b10 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Sun, 29 Oct 2017 22:13:40 -0400 Subject: [PATCH 06/20] Remove unused specs --- .../features/refinery/apis/admin/apis_spec.rb | 98 ------------------- api/spec/models/refinery/apis/api_spec.rb | 18 ---- api/spec/support/factories/refinery/apis.rb | 7 -- 3 files changed, 123 deletions(-) delete mode 100644 api/spec/features/refinery/apis/admin/apis_spec.rb delete mode 100644 api/spec/models/refinery/apis/api_spec.rb delete mode 100644 api/spec/support/factories/refinery/apis.rb diff --git a/api/spec/features/refinery/apis/admin/apis_spec.rb b/api/spec/features/refinery/apis/admin/apis_spec.rb deleted file mode 100644 index 569b57d537..0000000000 --- a/api/spec/features/refinery/apis/admin/apis_spec.rb +++ /dev/null @@ -1,98 +0,0 @@ -# encoding: utf-8 -require "spec_helper" - -describe Refinery do - describe "Apis" do - describe "Admin" do - describe "api", type: :feature do - refinery_login - - describe "api list" do - before do - FactoryGirl.create(:api, :title => "UniqueTitleOne") - FactoryGirl.create(:api, :title => "UniqueTitleTwo") - end - - it "shows two items" do - visit refinery.apis_admin_apis_path - expect(page).to have_content("UniqueTitleOne") - expect(page).to have_content("UniqueTitleTwo") - end - end - - describe "create" do - before do - visit refinery.apis_admin_apis_path - - click_link "Add New Api" - end - - context "valid data" do - it "should succeed" do - fill_in "Title", :with => "This is a test of the first string field" - expect { click_button "Save" }.to change(Refinery::Apis::Api, :count).from(0).to(1) - - expect(page).to have_content("'This is a test of the first string field' was successfully added.") - end - end - - context "invalid data" do - it "should fail" do - expect { click_button "Save" }.not_to change(Refinery::Apis::Api, :count) - - expect(page).to have_content("Title can't be blank") - end - end - - context "duplicate" do - before { FactoryGirl.create(:api, :title => "UniqueTitle") } - - it "should fail" do - visit refinery.apis_admin_apis_path - - click_link "Add New Api" - - fill_in "Title", :with => "UniqueTitle" - expect { click_button "Save" }.not_to change(Refinery::Apis::Api, :count) - - expect(page).to have_content("There were problems") - end - end - - end - - describe "edit" do - before { FactoryGirl.create(:api, :title => "A title") } - - it "should succeed" do - visit refinery.apis_admin_apis_path - - within ".actions" do - click_link "Edit this api" - end - - fill_in "Title", :with => "A different title" - click_button "Save" - - expect(page).to have_content("'A different title' was successfully updated.") - expect(page).not_to have_content("A title") - end - end - - describe "destroy" do - before { FactoryGirl.create(:api, :title => "UniqueTitleOne") } - - it "should succeed" do - visit refinery.apis_admin_apis_path - - click_link "Remove this api forever" - - expect(page).to have_content("'UniqueTitleOne' was successfully removed.") - expect(Refinery::Apis::Api.count).to eq(0) - end - end - - end - end - end -end diff --git a/api/spec/models/refinery/apis/api_spec.rb b/api/spec/models/refinery/apis/api_spec.rb deleted file mode 100644 index 2192ed77b4..0000000000 --- a/api/spec/models/refinery/apis/api_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' - -module Refinery - module Apis - describe Api do - describe "validations", type: :model do - subject do - FactoryGirl.create(:api, - :title => "Refinery CMS") - end - - it { should be_valid } - its(:errors) { should be_empty } - its(:title) { should == "Refinery CMS" } - end - end - end -end diff --git a/api/spec/support/factories/refinery/apis.rb b/api/spec/support/factories/refinery/apis.rb deleted file mode 100644 index be32c4e82d..0000000000 --- a/api/spec/support/factories/refinery/apis.rb +++ /dev/null @@ -1,7 +0,0 @@ - -FactoryGirl.define do - factory :api, :class => Refinery::Apis::Api do - sequence(:title) { |n| "refinery#{n}" } - end -end - From ccf8e32daa7273094d25fcadbadafa25222bd7d9 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Sun, 29 Oct 2017 23:36:59 -0400 Subject: [PATCH 07/20] Refactor Pages module --- .../graph/refinery/api/fields/page_field.rb | 19 --------- .../refinery/api/fields/pages/page_field.rb | 21 ++++++++++ .../refinery/api/fields/pages/pages_field.rb | 20 ++++++++++ .../refinery/api/types/page_part_type.rb | 21 ---------- api/app/graph/refinery/api/types/page_type.rb | 39 ------------------- .../api/types/pages/page_part_type.rb | 23 +++++++++++ .../refinery/api/types/pages/page_type.rb | 39 +++++++++++++++++++ .../graph/refinery/api/types/query_type.rb | 4 +- 8 files changed, 105 insertions(+), 81 deletions(-) delete mode 100644 api/app/graph/refinery/api/fields/page_field.rb create mode 100644 api/app/graph/refinery/api/fields/pages/page_field.rb create mode 100644 api/app/graph/refinery/api/fields/pages/pages_field.rb delete mode 100644 api/app/graph/refinery/api/types/page_part_type.rb delete mode 100644 api/app/graph/refinery/api/types/page_type.rb create mode 100644 api/app/graph/refinery/api/types/pages/page_part_type.rb create mode 100644 api/app/graph/refinery/api/types/pages/page_type.rb diff --git a/api/app/graph/refinery/api/fields/page_field.rb b/api/app/graph/refinery/api/fields/page_field.rb deleted file mode 100644 index 33b6b8eb95..0000000000 --- a/api/app/graph/refinery/api/fields/page_field.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Fields - PageField = GraphQL::Field.define do - name 'Page' - description 'Find a page by ID' - - type Types::PageType - argument :id, !types.ID - - resolve -> (obj, args, ctx) { - Refinery::Page.find_by_id(args[:id]) - } - end - end - end -end \ No newline at end of file diff --git a/api/app/graph/refinery/api/fields/pages/page_field.rb b/api/app/graph/refinery/api/fields/pages/page_field.rb new file mode 100644 index 0000000000..07b9992335 --- /dev/null +++ b/api/app/graph/refinery/api/fields/pages/page_field.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Fields + module Pages + PageField = GraphQL::Field.define do + name 'Page' + description 'Find a page by ID' + + type Types::Pages::PageType + argument :id, !types.ID + + resolve -> (obj, args, ctx) { + Refinery::Page.find_by_id(args[:id]) + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/fields/pages/pages_field.rb b/api/app/graph/refinery/api/fields/pages/pages_field.rb new file mode 100644 index 0000000000..cb1048503b --- /dev/null +++ b/api/app/graph/refinery/api/fields/pages/pages_field.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Fields + module Pages + PagesField = GraphQL::Field.define do + name 'Pages' + description 'Find all pages' + + type types[Types::Pages::PageType] + + resolve -> (obj, args, ctx) { + Refinery::Page.all + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/page_part_type.rb b/api/app/graph/refinery/api/types/page_part_type.rb deleted file mode 100644 index 6abe259214..0000000000 --- a/api/app/graph/refinery/api/types/page_part_type.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Types - PagePartType = GraphQL::ObjectType.define do - name "PagePart" - description "A PagePart" - - interfaces [Types::ActiveRecordInterface] - - field :slug, types.String - field :position, types.Int - field :title, types.String - - field :locale, types.String - field :body, types.String - end - end - end -end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/page_type.rb b/api/app/graph/refinery/api/types/page_type.rb deleted file mode 100644 index dc152b2e5d..0000000000 --- a/api/app/graph/refinery/api/types/page_type.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Types - PageType = GraphQL::ObjectType.define do - name "Page" - description "A Page" - - interfaces [Types::ActiveRecordInterface] - - field :parent_id, types.Int - field :path, types.String - field :show_in_menu, types.Boolean - field :link_url, types.String - field :menu_match, types.String - field :deletable, types.Boolean - field :draft, types.Boolean - field :skip_to_first_child, types.Boolean - field :lft, types.Int - field :rgt, types.Int - field :depth, types.Int - field :view_template, types.String - field :layout_template, types.String - - field :locale, types.String - field :title, types.String - field :custom_slug, types.String - field :menu_title, types.String - field :slug, types.String - - field :meta_description, types.String - field :browser_title, types.String - - field :parts, types[Types::PagePartType] - end - end - end -end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/pages/page_part_type.rb b/api/app/graph/refinery/api/types/pages/page_part_type.rb new file mode 100644 index 0000000000..fc5acc0a7f --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_part_type.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + PagePartType = GraphQL::ObjectType.define do + name "PagePart" + description "A PagePart" + + interfaces [Types::ActiveRecordInterface] + + field :slug, types.String + field :position, types.Int + field :title, types.String + + field :locale, types.String + field :body, types.String + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/pages/page_type.rb b/api/app/graph/refinery/api/types/pages/page_type.rb new file mode 100644 index 0000000000..d2867767f0 --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + PageType = GraphQL::ObjectType.define do + name "Page" + description "A Page" + + interfaces [Types::ActiveRecordInterface] + + field :parent_id, types.Int + field :path, types.String + field :show_in_menu, types.Boolean + field :link_url, types.String + field :menu_match, types.String + field :deletable, types.Boolean + field :draft, types.Boolean + field :skip_to_first_child, types.Boolean + field :lft, types.Int + field :rgt, types.Int + field :depth, types.Int + field :view_template, types.String + field :layout_template, types.String + field :locale, types.String + field :title, types.String + field :custom_slug, types.String + field :menu_title, types.String + field :slug, types.String + field :meta_description, types.String + field :browser_title, types.String + + field :parts, types[Types::Pages::PagePartType] + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/query_type.rb b/api/app/graph/refinery/api/types/query_type.rb index d915e598f1..475ebd5d0b 100644 --- a/api/app/graph/refinery/api/types/query_type.rb +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -7,8 +7,8 @@ module Types name 'Query' description 'The query root of this schema' - field :page, field: Fields::PageField - # field :pages, field: Refinery::Api::Fields::PagesField + field :page, field: Fields::Pages::PageField + field :pages, field: Fields::Pages::PagesField end end end From 68e0ccc39607b375254563b020568afe26a3058a Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Mon, 30 Oct 2017 00:40:24 -0400 Subject: [PATCH 08/20] Add basic pages field spec --- .../api/fields/pages/pages_field_spec.rb | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb diff --git a/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb new file mode 100644 index 0000000000..e7c03870fc --- /dev/null +++ b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Fields + module Pages + describe 'PagesField' do + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { { } } + let(:variables) { {} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +query { + pages { + title + } +} + QUERY + end + + context "as a normal user" do + it 'returns the page fields' do + page_result = result['data']['pages'].first + expect(page_result).to include( + 'title' => page.title, + ) + end + end + end + end + end + end + end From b4a8236517fe95c7d34f98a8eba0152d297477c8 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:21:58 -0500 Subject: [PATCH 09/20] Add basic specs for page and pages fields queries --- .../api/fields/pages/page_field_spec.rb | 48 +++++++++++++++++++ .../api/fields/pages/pages_field_spec.rb | 12 ++--- 2 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 api/spec/graph/refinery/api/fields/pages/page_field_spec.rb diff --git a/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb b/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb new file mode 100644 index 0000000000..7b5b5a132a --- /dev/null +++ b/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Fields + module Pages + describe 'PageField' do + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { { } } + let(:variables) { { } } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +query($id: ID!) { + page(id: $id) { + title + } +} + QUERY + end + + context "as a normal user" do + let(:variables) do + {'query' => '', 'id' => page.id } + end + + it 'returns a page' do + result_page = result['data']['page'] + expect(result_page['title']).to eq(page.title) + end + end + end + end + end + end +end diff --git a/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb index e7c03870fc..8d51bc0011 100644 --- a/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb +++ b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb @@ -8,10 +8,10 @@ module Fields module Pages describe 'PagesField' do - let!(:page) { FactoryBot.create(:page) } + let!(:page) { FactoryBot.create_list(:page, 5) } let(:context) { { } } - let(:variables) { {} } + let(:variables) { { } } let(:result) do GraphqlSchema.execute( @@ -32,11 +32,9 @@ module Pages end context "as a normal user" do - it 'returns the page fields' do - page_result = result['data']['pages'].first - expect(page_result).to include( - 'title' => page.title, - ) + it 'returns the pages' do + pages = result['data']['pages'] + expect(pages.length).to eq(5) end end end From 92788ccfcbe92a5ba82b525d22d10cbca9446011 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:22:31 -0500 Subject: [PATCH 10/20] field parts is now ordered by position in grapnel --- api/app/graph/refinery/api/types/pages/page_type.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/app/graph/refinery/api/types/pages/page_type.rb b/api/app/graph/refinery/api/types/pages/page_type.rb index d2867767f0..382734d2bb 100644 --- a/api/app/graph/refinery/api/types/pages/page_type.rb +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -31,7 +31,13 @@ module Pages field :meta_description, types.String field :browser_title, types.String - field :parts, types[Types::Pages::PagePartType] + field :parts do + type types[Types::Pages::PagePartType] + + resolve -> (obj, args, ctx) { + obj.parts.order(:position) + } + end end end end From 2924c9da3da89dfd7814b25f08eaf3c94ed85051 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:22:59 -0500 Subject: [PATCH 11/20] Add 'api' as friendly_id_reserved_words in pages configuration --- pages/lib/refinery/pages/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/lib/refinery/pages/configuration.rb b/pages/lib/refinery/pages/configuration.rb index b2863e926e..1cdd7db2be 100644 --- a/pages/lib/refinery/pages/configuration.rb +++ b/pages/lib/refinery/pages/configuration.rb @@ -62,7 +62,7 @@ def layout_template_whitelist self.types = Types.registered self.auto_expand_admin_tree = true self.friendly_id_reserved_words = %w( - index new session login logout users refinery admin images + index new session login logout users refinery admin images api ) self.layout_templates_pattern = 'app', 'views', '{layouts,refinery/layouts}', '*html*' self.view_templates_pattern = 'app', 'views', '{pages,refinery/pages}', '*html*' From ce25ed8ed65a8c309025474f5f720e4a85e8bfc6 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:48:20 -0500 Subject: [PATCH 12/20] WIP: Add mutations for pages --- api/app/graph/refinery/api/graphql_schema.rb | 2 +- .../refinery/api/inputs/pages/page_input.rb | 36 +++++++++ .../api/inputs/pages/page_part_input.rb | 20 +++++ .../api/mutations/pages/page_mutations.rb | 60 +++++++++++++++ .../graph/refinery/api/types/mutation_type.rb | 16 ++++ .../api/fields/pages/page_field_spec.rb | 6 +- .../api/fields/pages/pages_field_spec.rb | 8 +- .../mutations/pages/page_mutations_spec.rb | 73 +++++++++++++++++++ 8 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 api/app/graph/refinery/api/inputs/pages/page_input.rb create mode 100644 api/app/graph/refinery/api/inputs/pages/page_part_input.rb create mode 100644 api/app/graph/refinery/api/mutations/pages/page_mutations.rb create mode 100644 api/app/graph/refinery/api/types/mutation_type.rb create mode 100644 api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb diff --git a/api/app/graph/refinery/api/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb index 78f91112e2..5c457b4dcf 100644 --- a/api/app/graph/refinery/api/graphql_schema.rb +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -4,7 +4,7 @@ module Refinery module Api GraphqlSchema = GraphQL::Schema.define do query Types::QueryType - # mutation Types::MutationType + mutation Types::MutationType resolve_type -> (obj, args, ctx) { type_name = obj.class.name diff --git a/api/app/graph/refinery/api/inputs/pages/page_input.rb b/api/app/graph/refinery/api/inputs/pages/page_input.rb new file mode 100644 index 0000000000..f6d3ac6166 --- /dev/null +++ b/api/app/graph/refinery/api/inputs/pages/page_input.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Inputs + module Pages + PageInput = GraphQL::InputObjectType.define do + name 'PageInput' + + input_field :parent_id, types.Int + input_field :path, types.String + input_field :show_in_menu, types.Boolean + input_field :link_url, types.String + input_field :menu_match, types.String + input_field :deletable, types.Boolean + input_field :draft, types.Boolean + input_field :skip_to_first_child, types.Boolean + input_field :lft, types.Int + input_field :rgt, types.Int + input_field :depth, types.Int + input_field :view_template, types.String + input_field :layout_template, types.String + input_field :locale, types.String + input_field :title, types.String + input_field :custom_slug, types.String + input_field :menu_title, types.String + input_field :slug, types.String + input_field :meta_description, types.String + input_field :browser_title, types.String + + input_field :parts, types[Inputs::Pages::PagePartInput] + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/inputs/pages/page_part_input.rb b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb new file mode 100644 index 0000000000..33f52a5cfc --- /dev/null +++ b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Inputs + module Pages + PagePartInput = GraphQL::InputObjectType.define do + name 'PagePartInput' + + input_field :slug, types.String + input_field :position, types.Int + input_field :title, types.String + + input_field :locale, types.String + input_field :body, types.String + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb new file mode 100644 index 0000000000..42d2e3d8f2 --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module Pages + module PageMutations + Create = GraphQL::Relay::Mutation.define do + name 'CreatePage' + description 'Create a page' + + input_field :page, !Inputs::Pages::PageInput + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + inputs = inputs.to_h.deep_symbolize_keys + + page = Refinery::Page.create!(inputs[:page]) + + { page: page } + } + end + + Update = GraphQL::Relay::Mutation.define do + name 'UpdatePage' + description 'Create a page' + + input_field :id, !types.ID + input_field :page, !Inputs::Pages::PageInput + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + inputs = inputs.to_h.deep_symbolize_keys + + Refinery::Page.update(inputs[:id], inputs[:page]) + + { page: page } + } + end + + Delete = GraphQL::Relay::Mutation.define do + name 'DeletePage' + + input_field :id, !types.ID + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + page = Refinery::Page.destroy(inputs[:id]) + + { page: page } + } + end + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/mutation_type.rb b/api/app/graph/refinery/api/types/mutation_type.rb new file mode 100644 index 0000000000..671e5f2a6c --- /dev/null +++ b/api/app/graph/refinery/api/types/mutation_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + MutationType = GraphQL::ObjectType.define do + name 'Mutation' + description 'The mutation root for this schema' + + field :create_page, field: Mutations::Pages::PageMutations::Create.field + field :update_page, field: Mutations::Pages::PageMutations::Update.field + field :delete_page, field: Mutations::Pages::PageMutations::Delete.field + end + end + end +end \ No newline at end of file diff --git a/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb b/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb index 7b5b5a132a..07d811e4db 100644 --- a/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb +++ b/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb @@ -31,14 +31,16 @@ module Pages QUERY end + subject { result } + context "as a normal user" do let(:variables) do {'query' => '', 'id' => page.id } end it 'returns a page' do - result_page = result['data']['page'] - expect(result_page['title']).to eq(page.title) + subject + expect(result['data']['page']['title']).to eq(page.title) end end end diff --git a/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb index 8d51bc0011..dfb8a8db4b 100644 --- a/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb +++ b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb @@ -8,7 +8,7 @@ module Fields module Pages describe 'PagesField' do - let!(:page) { FactoryBot.create_list(:page, 5) } + let!(:pages) { FactoryBot.create_list(:page, 5) } let(:context) { { } } let(:variables) { { } } @@ -31,10 +31,12 @@ module Pages QUERY end + subject { result } + context "as a normal user" do it 'returns the pages' do - pages = result['data']['pages'] - expect(pages.length).to eq(5) + subject + expect(result['data']['pages'].length).to eq(5) end end end diff --git a/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb b/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb new file mode 100644 index 0000000000..78210a32b1 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'DeletePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: DeletePageInput!) { + delete_page(input: $page) { + page { + id + } + } +} + QUERY + end + + subject { result } + + context 'Correct page id' do + let(:variables) { {'page': { 'id': page.id }} } + + it 'deletes the page' do + subject + expect(Refinery::Page.find_by_id(page.id)).to be(nil) + end + end + + context 'Incorrect page id' do + let(:variables) { {'page': { 'id': 1000 }} } + + it 'does not delete the page' do + subject + expect(Refinery::Page.find_by_id(page.id)).to_not be(nil) + end + end + + context 'Current user does not exist' do + let(:variables) { {'page': { 'id': page.id }} } + let(:context) { {current_user: nil} } + + it 'returns an error' do + expect(subject['errors']). + to include(include('message' => "You're not authorized to do this")) + end + + it 'returns no data' do + expect(subject['data']['delete_page']).to be(nil) + end + end + end + end + end + end +end From 91a2805f7f9b39ca4fdd8228969788d47a175f3f Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Mon, 20 Nov 2017 23:01:21 -0500 Subject: [PATCH 13/20] Update travis config to support api env --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6d0e6c9715..3a3cf71799 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,12 @@ env: - DB=postgresql EXTENSION=pages - DB=postgresql EXTENSION=images - DB=postgresql EXTENSION=resources + - DB=postgresql EXTENSION=api - DB=mysql EXTENSION=core - DB=mysql EXTENSION=pages - DB=mysql EXTENSION=images - DB=mysql EXTENSION=resources + - DB=mysql EXTENSION=api notifications: email: true irc: From d8ad1fde299b2654eb727103f8ab863186b09b47 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Mon, 20 Nov 2017 23:57:51 -0500 Subject: [PATCH 14/20] We now use Admin controller for mutations --- .../{api => admin}/graphql_controller.rb | 4 +-- api/config/routes.rb | 4 +-- .../mutations/pages/page_mutations_spec.rb | 25 +------------------ 3 files changed, 5 insertions(+), 28 deletions(-) rename api/app/controllers/refinery/{api => admin}/graphql_controller.rb (86%) diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/admin/graphql_controller.rb similarity index 86% rename from api/app/controllers/refinery/api/graphql_controller.rb rename to api/app/controllers/refinery/admin/graphql_controller.rb index 251dec00c7..6cc5a2b129 100644 --- a/api/app/controllers/refinery/api/graphql_controller.rb +++ b/api/app/controllers/refinery/admin/graphql_controller.rb @@ -1,6 +1,6 @@ module Refinery - module Api - class GraphqlController < ::ApplicationController + module Admin + class GraphqlController < Refinery::AdminController def execute query = params[:query] diff --git a/api/config/routes.rb b/api/config/routes.rb index 30469b118f..73ee215eb0 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -1,9 +1,9 @@ Refinery::Core::Engine.routes.draw do - namespace :api do + namespace :admin, path: Refinery::Core.backend_route do post 'graphql' => 'graphql#execute' if Rails.env.development? - mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/api/graphql" + mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/#{Refinery::Core.backend_route}/graphql" end end end diff --git a/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb b/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb index 78210a32b1..8d91c662c2 100644 --- a/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb +++ b/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb @@ -36,36 +36,13 @@ module Pages subject { result } context 'Correct page id' do - let(:variables) { {'page': { 'id': page.id }} } + let(:variables) { {'page' => { 'id' => page.id }} } it 'deletes the page' do subject expect(Refinery::Page.find_by_id(page.id)).to be(nil) end end - - context 'Incorrect page id' do - let(:variables) { {'page': { 'id': 1000 }} } - - it 'does not delete the page' do - subject - expect(Refinery::Page.find_by_id(page.id)).to_not be(nil) - end - end - - context 'Current user does not exist' do - let(:variables) { {'page': { 'id': page.id }} } - let(:context) { {current_user: nil} } - - it 'returns an error' do - expect(subject['errors']). - to include(include('message' => "You're not authorized to do this")) - end - - it 'returns no data' do - expect(subject['data']['delete_page']).to be(nil) - end - end end end end From d0ad52ec1fbdaee825dec198a41a0857a4d47855 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 29 Nov 2017 22:00:11 -0500 Subject: [PATCH 15/20] context is now a private method in GrahqlController It will be easier to override --- .../controllers/refinery/admin/graphql_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/app/controllers/refinery/admin/graphql_controller.rb b/api/app/controllers/refinery/admin/graphql_controller.rb index 6cc5a2b129..9e7615457c 100644 --- a/api/app/controllers/refinery/admin/graphql_controller.rb +++ b/api/app/controllers/refinery/admin/graphql_controller.rb @@ -6,10 +6,6 @@ def execute query = params[:query] variables = params[:variables] || {} - context = { - current_user: current_refinery_user - } - begin result = Refinery::Api::GraphqlSchema.execute(query, variables: variables, context: context) rescue => error @@ -18,6 +14,14 @@ def execute render json: result end + + private + + def context + { + current_user: current_refinery_user + } + end end end end \ No newline at end of file From d17f717bba07fc09b1d355fe54de53f661e84f05 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 29 Nov 2017 22:00:52 -0500 Subject: [PATCH 16/20] Add page mutations specs Fix page update mutation --- .../api/mutations/pages/page_mutations.rb | 2 +- .../pages/create_page_mutation_spec.rb | 58 +++++++++++++++++ ...s_spec.rb => delete_page_mutation_spec.rb} | 0 .../pages/update_page_mutation_spec.rb | 63 +++++++++++++++++++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb rename api/spec/graph/refinery/api/mutations/pages/{page_mutations_spec.rb => delete_page_mutation_spec.rb} (100%) create mode 100644 api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb diff --git a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb index 42d2e3d8f2..8d9565ff18 100644 --- a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb +++ b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb @@ -34,7 +34,7 @@ module PageMutations resolve -> (obj, inputs, ctx) { inputs = inputs.to_h.deep_symbolize_keys - Refinery::Page.update(inputs[:id], inputs[:page]) + page = Refinery::Page.update(inputs[:id], inputs[:page]) { page: page } } diff --git a/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb new file mode 100644 index 0000000000..53d5723233 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'CreatePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: CreatePageInput!) { + create_page(input: $page) { + page { + title + } + } +} + QUERY + end + + subject { result } + + context 'as an admin' do + context 'create a page' do + let(:variables) do + { + 'page' => { + 'page' => { + 'title' => 'Test page' + } + } + } + end + + it 'returns the page title of the newly created page' do + subject + expect(result['data']['create_page']['page']['title']).to eq('Test page') + end + end + end + end + end + end + end +end diff --git a/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb similarity index 100% rename from api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb rename to api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb diff --git a/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb new file mode 100644 index 0000000000..cb6ea0b5b2 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'UpdatePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: UpdatePageInput!) { + update_page(input: $page) { + page { + id + title + } + } +} + QUERY + end + + subject { result } + + context 'as an admin' do + context 'update a page' do + let(:variables) do + { + 'page' => { + 'id' => page.id, + 'page' => { + 'title' => 'Updated Test page' + } + } + } + end + + it 'returns the page id and title of the newly created page' do + subject + expect(result['data']['update_page']['page']['id']).to eq(page.id.to_s) + expect(result['data']['update_page']['page']['title']).to eq('Updated Test page') + end + end + end + end + end + end + end +end From a41520f72bb70aa35050143cf96219dc72ea9ed8 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 00:08:45 -0400 Subject: [PATCH 17/20] WIP: Refactor graphql ruby with class name style --- .../refinery/api/fields/pages/page_field.rb | 2 +- .../refinery/api/fields/pages/pages_field.rb | 2 +- api/app/graph/refinery/api/graphql_schema.rb | 2 +- .../refinery/api/inputs/pages/page_input.rb | 2 +- .../api/inputs/pages/page_part_input.rb | 2 +- .../refinery/api/mutations/pages/create.rb | 26 ++++++++ .../refinery/api/mutations/pages/delete.rb | 23 +++++++ .../api/mutations/pages/page_mutations.rb | 60 ------------------- .../refinery/api/mutations/pages/update.rb | 27 +++++++++ .../refinery/api/types/base_interface.rb | 9 +++ .../graph/refinery/api/types/base_object.rb | 8 +++ .../graph/refinery/api/types/mutation_type.rb | 8 +-- .../api/types/pages/page_part_type.rb | 2 +- .../refinery/api/types/pages/page_type.rb | 2 +- .../graph/refinery/api/types/query_type.rb | 2 +- 15 files changed, 105 insertions(+), 72 deletions(-) create mode 100644 api/app/graph/refinery/api/mutations/pages/create.rb create mode 100644 api/app/graph/refinery/api/mutations/pages/delete.rb delete mode 100644 api/app/graph/refinery/api/mutations/pages/page_mutations.rb create mode 100644 api/app/graph/refinery/api/mutations/pages/update.rb create mode 100644 api/app/graph/refinery/api/types/base_interface.rb create mode 100644 api/app/graph/refinery/api/types/base_object.rb diff --git a/api/app/graph/refinery/api/fields/pages/page_field.rb b/api/app/graph/refinery/api/fields/pages/page_field.rb index 07b9992335..fc6609f303 100644 --- a/api/app/graph/refinery/api/fields/pages/page_field.rb +++ b/api/app/graph/refinery/api/fields/pages/page_field.rb @@ -4,7 +4,7 @@ module Refinery module Api module Fields module Pages - PageField = GraphQL::Field.define do + class PageField < GraphQL::Schema::Field name 'Page' description 'Find a page by ID' diff --git a/api/app/graph/refinery/api/fields/pages/pages_field.rb b/api/app/graph/refinery/api/fields/pages/pages_field.rb index cb1048503b..a3a1faafd0 100644 --- a/api/app/graph/refinery/api/fields/pages/pages_field.rb +++ b/api/app/graph/refinery/api/fields/pages/pages_field.rb @@ -4,7 +4,7 @@ module Refinery module Api module Fields module Pages - PagesField = GraphQL::Field.define do + class PagesField < GraphQL::Schema::Field name 'Pages' description 'Find all pages' diff --git a/api/app/graph/refinery/api/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb index 5c457b4dcf..b2b8b79534 100644 --- a/api/app/graph/refinery/api/graphql_schema.rb +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -2,7 +2,7 @@ module Refinery module Api - GraphqlSchema = GraphQL::Schema.define do + class GraphqlSchema < GraphQL::Schema query Types::QueryType mutation Types::MutationType diff --git a/api/app/graph/refinery/api/inputs/pages/page_input.rb b/api/app/graph/refinery/api/inputs/pages/page_input.rb index f6d3ac6166..814bdcbe72 100644 --- a/api/app/graph/refinery/api/inputs/pages/page_input.rb +++ b/api/app/graph/refinery/api/inputs/pages/page_input.rb @@ -4,7 +4,7 @@ module Refinery module Api module Inputs module Pages - PageInput = GraphQL::InputObjectType.define do + class PageInput < GraphQL::Schema::InputObject name 'PageInput' input_field :parent_id, types.Int diff --git a/api/app/graph/refinery/api/inputs/pages/page_part_input.rb b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb index 33f52a5cfc..8ba01e534a 100644 --- a/api/app/graph/refinery/api/inputs/pages/page_part_input.rb +++ b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb @@ -4,7 +4,7 @@ module Refinery module Api module Inputs module Pages - PagePartInput = GraphQL::InputObjectType.define do + class PagePartInput < GraphQL::Schema::InputObject name 'PagePartInput' input_field :slug, types.String diff --git a/api/app/graph/refinery/api/mutations/pages/create.rb b/api/app/graph/refinery/api/mutations/pages/create.rb new file mode 100644 index 0000000000..b6e87026ff --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/create.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module Pages + class Create < GraphQL::Schema::Mutation + name 'CreatePage' + description 'Create a page' + + input_field :page, !Inputs::Pages::PageInput + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + inputs = inputs.to_h.deep_symbolize_keys + + page = Refinery::Page.create!(inputs[:page]) + + { page: page } + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/delete.rb b/api/app/graph/refinery/api/mutations/pages/delete.rb new file mode 100644 index 0000000000..7a04b657a7 --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/delete.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module Pages + class Delete < GraphQL::Schema::Mutation + name 'DeletePage' + + input_field :id, !types.ID + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + page = Refinery::Page.destroy(inputs[:id]) + + { page: page } + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb deleted file mode 100644 index 8d9565ff18..0000000000 --- a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Mutations - module Pages - module PageMutations - Create = GraphQL::Relay::Mutation.define do - name 'CreatePage' - description 'Create a page' - - input_field :page, !Inputs::Pages::PageInput - - return_field :page, Types::Pages::PageType - - resolve -> (obj, inputs, ctx) { - inputs = inputs.to_h.deep_symbolize_keys - - page = Refinery::Page.create!(inputs[:page]) - - { page: page } - } - end - - Update = GraphQL::Relay::Mutation.define do - name 'UpdatePage' - description 'Create a page' - - input_field :id, !types.ID - input_field :page, !Inputs::Pages::PageInput - - return_field :page, Types::Pages::PageType - - resolve -> (obj, inputs, ctx) { - inputs = inputs.to_h.deep_symbolize_keys - - page = Refinery::Page.update(inputs[:id], inputs[:page]) - - { page: page } - } - end - - Delete = GraphQL::Relay::Mutation.define do - name 'DeletePage' - - input_field :id, !types.ID - - return_field :page, Types::Pages::PageType - - resolve -> (obj, inputs, ctx) { - page = Refinery::Page.destroy(inputs[:id]) - - { page: page } - } - end - end - end - end - end -end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/update.rb b/api/app/graph/refinery/api/mutations/pages/update.rb new file mode 100644 index 0000000000..db33db4b26 --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/update.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module Pages + class Update < GraphQL::Schema::Mutation + name 'UpdatePage' + description 'Create a page' + + input_field :id, !types.ID + input_field :page, !Inputs::Pages::PageInput + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + inputs = inputs.to_h.deep_symbolize_keys + + page = Refinery::Page.update(inputs[:id], inputs[:page]) + + { page: page } + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/base_interface.rb b/api/app/graph/refinery/api/types/base_interface.rb new file mode 100644 index 0000000000..500c20d2da --- /dev/null +++ b/api/app/graph/refinery/api/types/base_interface.rb @@ -0,0 +1,9 @@ +module Refinery + module Api + module Types + class BaseInterface + include GraphQL::Schema::Interface + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/base_object.rb b/api/app/graph/refinery/api/types/base_object.rb new file mode 100644 index 0000000000..18cb6f185c --- /dev/null +++ b/api/app/graph/refinery/api/types/base_object.rb @@ -0,0 +1,8 @@ +module Refinery + module Api + module Types + class BaseObject < GraphQL::Schema::Object + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/mutation_type.rb b/api/app/graph/refinery/api/types/mutation_type.rb index 671e5f2a6c..8ade6f2e31 100644 --- a/api/app/graph/refinery/api/types/mutation_type.rb +++ b/api/app/graph/refinery/api/types/mutation_type.rb @@ -3,13 +3,13 @@ module Refinery module Api module Types - MutationType = GraphQL::ObjectType.define do + class MutationType < Types::BaseObject name 'Mutation' description 'The mutation root for this schema' - field :create_page, field: Mutations::Pages::PageMutations::Create.field - field :update_page, field: Mutations::Pages::PageMutations::Update.field - field :delete_page, field: Mutations::Pages::PageMutations::Delete.field + field :createPage, mutation: Mutations::Pages::Create + field :updatePage, mutation: Mutations::Pages::Update + field :deletePage, mutation: Mutations::Pages::Delete end end end diff --git a/api/app/graph/refinery/api/types/pages/page_part_type.rb b/api/app/graph/refinery/api/types/pages/page_part_type.rb index fc5acc0a7f..b57a23f724 100644 --- a/api/app/graph/refinery/api/types/pages/page_part_type.rb +++ b/api/app/graph/refinery/api/types/pages/page_part_type.rb @@ -4,7 +4,7 @@ module Refinery module Api module Types module Pages - PagePartType = GraphQL::ObjectType.define do + class PagePartType < GraphQL::Schema::Object name "PagePart" description "A PagePart" diff --git a/api/app/graph/refinery/api/types/pages/page_type.rb b/api/app/graph/refinery/api/types/pages/page_type.rb index 382734d2bb..569b6119c6 100644 --- a/api/app/graph/refinery/api/types/pages/page_type.rb +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -4,7 +4,7 @@ module Refinery module Api module Types module Pages - PageType = GraphQL::ObjectType.define do + class PageType < GraphQL::Schema::Object name "Page" description "A Page" diff --git a/api/app/graph/refinery/api/types/query_type.rb b/api/app/graph/refinery/api/types/query_type.rb index 475ebd5d0b..13cb7fee1d 100644 --- a/api/app/graph/refinery/api/types/query_type.rb +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -3,7 +3,7 @@ module Refinery module Api module Types - QueryType = GraphQL::ObjectType.define do + class QueryType < Types::BaseObject name 'Query' description 'The query root of this schema' From 12fd295af0e38dba6b709f0f503700c2f0040657 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 08:02:04 -0400 Subject: [PATCH 18/20] Remove unused ApiGenerator --- api/lib/generators/refinery/api_generator.rb | 19 ------------------- api/lib/refinery/api.rb | 2 -- 2 files changed, 21 deletions(-) delete mode 100644 api/lib/generators/refinery/api_generator.rb diff --git a/api/lib/generators/refinery/api_generator.rb b/api/lib/generators/refinery/api_generator.rb deleted file mode 100644 index d9e04600b2..0000000000 --- a/api/lib/generators/refinery/api_generator.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Refinery - class ApiGenerator < Rails::Generators::Base - - def rake_db - rake "refinery_api:install:migrations" - end - - def append_load_seed_data - create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb')) - append_file 'db/seeds.rb', :verbose => true do - <<-EOH - -# Added by Refinery CMS Apis extension -Refinery::Api::Engine.load_seed - EOH - end - end - end -end diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb index 682f91f60e..2942426761 100644 --- a/api/lib/refinery/api.rb +++ b/api/lib/refinery/api.rb @@ -3,8 +3,6 @@ require 'graphiql/rails' module Refinery - autoload :ApiGenerator, 'generators/refinery/api_generator' - module Api require 'refinery/api/engine' From 6681bfe94aa44e771c1bcaeafbe039758c88d2c3 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 08:02:31 -0400 Subject: [PATCH 19/20] Move GraphQL controller outside Admin namespace --- .../controllers/refinery/{admin => api}/graphql_controller.rb | 2 +- api/config/routes.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename api/app/controllers/refinery/{admin => api}/graphql_controller.rb (96%) diff --git a/api/app/controllers/refinery/admin/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb similarity index 96% rename from api/app/controllers/refinery/admin/graphql_controller.rb rename to api/app/controllers/refinery/api/graphql_controller.rb index 9e7615457c..b8afb935b1 100644 --- a/api/app/controllers/refinery/admin/graphql_controller.rb +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -1,5 +1,5 @@ module Refinery - module Admin + module Api class GraphqlController < Refinery::AdminController def execute diff --git a/api/config/routes.rb b/api/config/routes.rb index 73ee215eb0..5118f2cad5 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -1,5 +1,5 @@ Refinery::Core::Engine.routes.draw do - namespace :admin, path: Refinery::Core.backend_route do + namespace :api do post 'graphql' => 'graphql#execute' if Rails.env.development? From 720da16f2f8ccdebdcaab92ecc53394e301d21e7 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 08:02:54 -0400 Subject: [PATCH 20/20] Update GraphQL gem dependency version --- api/refinerycms-api.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec index 4fda0df90e..0920c93c89 100644 --- a/api/refinerycms-api.gemspec +++ b/api/refinerycms-api.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| # Runtime dependencies s.add_dependency 'refinerycms-core', version - s.add_dependency 'graphql', '~> 1.7' + s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5' s.add_dependency 'graphiql-rails', '~> 1.4' # Development dependencies (usually used for testing)