From 464a5d1fe928d3aab96b946ab19960136e09afb0 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 24 Oct 2017 23:23:36 -0400 Subject: [PATCH 01/32] 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 3a361ae991c9f7d46395e8bc7a5fdad81da71ad4 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 24 Oct 2017 23:24:00 -0400 Subject: [PATCH 02/32] 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 20880a9fc0..d1625db34e 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 'bootsnap', require: false 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 9b3d4e0fd3e249d3cd8ed2d1adc0a95c737b7600 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 24 Oct 2017 23:45:26 -0400 Subject: [PATCH 03/32] 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 711360764d4cdc76fd74a0713ba7de0e5243cb6a Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Oct 2017 00:25:49 -0400 Subject: [PATCH 04/32] 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 83b28fbd224fb0a9d24161a0e322411e9821b99f Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 26 Oct 2017 22:47:37 -0400 Subject: [PATCH 05/32] 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 2ebf98016731eb4737d066c5b96adf4bf1809e37 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Sun, 29 Oct 2017 22:13:40 -0400 Subject: [PATCH 06/32] 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 6ec5fc0637bdeea271b1dc18dbd3cd001ad6e7c8 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Sun, 29 Oct 2017 23:36:59 -0400 Subject: [PATCH 07/32] 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 b3218efb53c111becff94ba4b095b4a8a22d9d6a Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Mon, 30 Oct 2017 00:40:24 -0400 Subject: [PATCH 08/32] 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 a47a95ca5c83e84ee7a6507f2c1673523e52fa22 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:21:58 -0500 Subject: [PATCH 09/32] 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 4c8a93e58b5e9d2f0d01e90203bf77995d2f5ad0 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:22:31 -0500 Subject: [PATCH 10/32] 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 061c300cba71fc7f833fb19d4279e0151caa3e67 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:22:59 -0500 Subject: [PATCH 11/32] 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 b4af6658ae..39e47e8f22 100644 --- a/pages/lib/refinery/pages/configuration.rb +++ b/pages/lib/refinery/pages/configuration.rb @@ -63,7 +63,7 @@ def layout_template_whitelist self.auto_expand_admin_tree = true self.reserved_paths = %w(/rails/active_storage) 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.reserved_paths.map { |path| path.split('/').reject(&:blank?).first}.flatten.uniq self.layout_templates_pattern = 'app', 'views', '{layouts,refinery/layouts}', '*html*' self.view_templates_pattern = 'app', 'views', '{pages,refinery/pages}', '*html*' From c39fb2907d16c6e2dcb2f33a6da90ec76a557357 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 16 Nov 2017 21:48:20 -0500 Subject: [PATCH 12/32] 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 234c399ac5bc4125c42867fe3faabc5a2a99a91a Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Mon, 20 Nov 2017 23:01:21 -0500 Subject: [PATCH 13/32] Update travis config to support api env --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d8e636a8a4..22a2ea22c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,11 +27,13 @@ env: - DB=postgresql EXTENSION=pages - DB=postgresql EXTENSION=images - DB=postgresql EXTENSION=resources + - DB=postgresql EXTENSION=api - DB=mysql EXTENSION=core - DB=mysql EXTENSION=dragonfly - DB=mysql EXTENSION=pages - DB=mysql EXTENSION=images - DB=mysql EXTENSION=resources + - DB=mysql EXTENSION=api notifications: email: true webhooks: From 38142e26d3c6221a64046b97111b9285dfa0f9b9 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Mon, 20 Nov 2017 23:57:51 -0500 Subject: [PATCH 14/32] 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 34b576c1894ad074dbc7ffb5eb3dd7af7c4d3b49 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 29 Nov 2017 22:00:11 -0500 Subject: [PATCH 15/32] 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 e77abf2b42c7b0e5cd6d9ad20c213c8f996852af Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 29 Nov 2017 22:00:52 -0500 Subject: [PATCH 16/32] 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 3c996b892fafe1aab072c83ae9db500e17c4d903 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 00:08:45 -0400 Subject: [PATCH 17/32] 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 97ceaf3fe5decaa5d8058f897c86c4a99a1057af Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 08:02:04 -0400 Subject: [PATCH 18/32] 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 dc423d08d1139f6ae1f2abcf54d874a1199e202c Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 08:02:31 -0400 Subject: [PATCH 19/32] 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 (97%) diff --git a/api/app/controllers/refinery/admin/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb similarity index 97% 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 c123659cdc65cc2b51943244eb6738bb141f6950 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 25 Jul 2018 08:02:54 -0400 Subject: [PATCH 20/32] 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) From 30b09c5dc666efed09edc4758d3a0f087788d81b Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 4 Sep 2018 21:55:51 -0400 Subject: [PATCH 21/32] WIP: Update to GraphQL 1.8 --- .../refinery/api/graphql_controller.rb | 44 +++++++++++---- .../pages/page_field.rb | 2 +- .../pages/pages_field.rb | 2 +- api/app/graph/refinery/api/graphql_schema.rb | 9 +--- .../refinery/api/inputs/pages/page_input.rb | 2 +- .../api/inputs/pages/page_part_input.rb | 2 +- .../refinery/api/mutations/base_mutation.rb | 8 +++ .../refinery/api/mutations/pages/create.rb | 6 +-- .../refinery/api/mutations/pages/delete.rb | 10 ++-- .../refinery/api/mutations/pages/update.rb | 2 +- .../api/resolvers/pages/page_resolver.rb | 21 ++++++++ .../api/types/active_record_interface.rb | 26 --------- api/app/graph/refinery/api/types/base_enum.rb | 8 +++ .../refinery/api/types/base_input_object.rb | 8 +++ .../graph/refinery/api/types/base_union.rb | 8 +++ api/app/graph/refinery/api/types/date_type.rb | 2 +- .../graph/refinery/api/types/mutation_type.rb | 2 +- .../api/types/pages/page_part_type.rb | 14 +++-- .../refinery/api/types/pages/page_type.rb | 53 ++++++++----------- .../graph/refinery/api/types/query_type.rb | 14 +++-- api/config/routes.rb | 4 +- api/lib/refinery/api.rb | 1 - api/license.md | 2 +- api/refinerycms-api.gemspec | 6 +-- .../api/fields/pages/page_field_spec.rb | 1 + 25 files changed, 151 insertions(+), 106 deletions(-) rename api/app/graph/refinery/api/{fields => fields_deprecated}/pages/page_field.rb (93%) rename api/app/graph/refinery/api/{fields => fields_deprecated}/pages/pages_field.rb (91%) create mode 100644 api/app/graph/refinery/api/mutations/base_mutation.rb create mode 100644 api/app/graph/refinery/api/resolvers/pages/page_resolver.rb delete mode 100644 api/app/graph/refinery/api/types/active_record_interface.rb create mode 100644 api/app/graph/refinery/api/types/base_enum.rb create mode 100644 api/app/graph/refinery/api/types/base_input_object.rb create mode 100644 api/app/graph/refinery/api/types/base_union.rb diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb index b8afb935b1..a8ac6056bd 100644 --- a/api/app/controllers/refinery/api/graphql_controller.rb +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -1,18 +1,19 @@ module Refinery module Api - class GraphqlController < Refinery::AdminController - + class GraphqlController < ApplicationController def execute + variables = ensure_hash(params[:variables]) query = params[:query] - variables = params[:variables] || {} + operation_name = params[:operationName] - begin - result = Refinery::Api::GraphqlSchema.execute(query, variables: variables, context: context) - rescue => error - result = { errors: [{ message: error.message }] } - end + result = Refinery::Api::GraphqlSchema.execute( + query, variables: variables, context: context, operation_name: operation_name + ) render json: result + rescue => e + raise e unless Rails.env.development? + handle_error_in_development e end private @@ -22,6 +23,31 @@ def context current_user: current_refinery_user } end + + # Handle form data, JSON body, or a blank value + def ensure_hash(ambiguous_param) + case ambiguous_param + when String + if ambiguous_param.present? + ensure_hash(JSON.parse(ambiguous_param)) + else + {} + end + when Hash, ActionController::Parameters + ambiguous_param + when nil + {} + else + raise ArgumentError, "Unexpected parameter: #{ambiguous_param}" + end + end + + def handle_error_in_development(e) + logger.error e.message + logger.error e.backtrace.join("\n") + + render json: { error: { message: e.message, backtrace: e.backtrace }, data: {} }, status: 500 + end end end -end \ No newline at end of file +end diff --git a/api/app/graph/refinery/api/fields/pages/page_field.rb b/api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb similarity index 93% rename from api/app/graph/refinery/api/fields/pages/page_field.rb rename to api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb index fc6609f303..f756576871 100644 --- a/api/app/graph/refinery/api/fields/pages/page_field.rb +++ b/api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb @@ -5,7 +5,7 @@ module Api module Fields module Pages class PageField < GraphQL::Schema::Field - name 'Page' + graphql_name 'Page' description 'Find a page by ID' type Types::Pages::PageType diff --git a/api/app/graph/refinery/api/fields/pages/pages_field.rb b/api/app/graph/refinery/api/fields_deprecated/pages/pages_field.rb similarity index 91% rename from api/app/graph/refinery/api/fields/pages/pages_field.rb rename to api/app/graph/refinery/api/fields_deprecated/pages/pages_field.rb index a3a1faafd0..c047732b52 100644 --- a/api/app/graph/refinery/api/fields/pages/pages_field.rb +++ b/api/app/graph/refinery/api/fields_deprecated/pages/pages_field.rb @@ -5,7 +5,7 @@ module Api module Fields module Pages class PagesField < GraphQL::Schema::Field - name 'Pages' + graphql_name 'Pages' description 'Find all pages' type types[Types::Pages::PageType] diff --git a/api/app/graph/refinery/api/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb index b2b8b79534..cacc028e25 100644 --- a/api/app/graph/refinery/api/graphql_schema.rb +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -3,13 +3,8 @@ module Refinery module Api class GraphqlSchema < GraphQL::Schema + # mutation Types::MutationType query Types::QueryType - mutation Types::MutationType - - resolve_type -> (obj, args, ctx) { - type_name = obj.class.name - Schema.types[type_name] - } end end -end +end \ No newline at end of file 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 814bdcbe72..6e47e2178a 100644 --- a/api/app/graph/refinery/api/inputs/pages/page_input.rb +++ b/api/app/graph/refinery/api/inputs/pages/page_input.rb @@ -5,7 +5,7 @@ module Api module Inputs module Pages class PageInput < GraphQL::Schema::InputObject - name 'PageInput' + graphql_name 'PageInput' input_field :parent_id, types.Int input_field :path, types.String 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 8ba01e534a..73e37a0921 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 @@ -5,7 +5,7 @@ module Api module Inputs module Pages class PagePartInput < GraphQL::Schema::InputObject - name 'PagePartInput' + graphql_name 'PagePartInput' input_field :slug, types.String input_field :position, types.Int diff --git a/api/app/graph/refinery/api/mutations/base_mutation.rb b/api/app/graph/refinery/api/mutations/base_mutation.rb new file mode 100644 index 0000000000..0bf8d42c63 --- /dev/null +++ b/api/app/graph/refinery/api/mutations/base_mutation.rb @@ -0,0 +1,8 @@ +module Refinery + module Api + module Mutations + class Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/create.rb b/api/app/graph/refinery/api/mutations/pages/create.rb index b6e87026ff..f9341d3abd 100644 --- a/api/app/graph/refinery/api/mutations/pages/create.rb +++ b/api/app/graph/refinery/api/mutations/pages/create.rb @@ -5,12 +5,12 @@ module Api module Mutations module Pages class Create < GraphQL::Schema::Mutation - name 'CreatePage' + graphql_name 'CreatePage' description 'Create a page' - input_field :page, !Inputs::Pages::PageInput + argument :page, !Types::Pages::PageType - return_field :page, Types::Pages::PageType + type Types::Pages::PageType resolve -> (obj, inputs, ctx) { inputs = inputs.to_h.deep_symbolize_keys diff --git a/api/app/graph/refinery/api/mutations/pages/delete.rb b/api/app/graph/refinery/api/mutations/pages/delete.rb index 7a04b657a7..4d80b78a30 100644 --- a/api/app/graph/refinery/api/mutations/pages/delete.rb +++ b/api/app/graph/refinery/api/mutations/pages/delete.rb @@ -4,15 +4,15 @@ module Refinery module Api module Mutations module Pages - class Delete < GraphQL::Schema::Mutation - name 'DeletePage' + class Delete < Mutations::BaseMutation + graphql_name 'DeletePage' - input_field :id, !types.ID + argument :id, ID, required: true return_field :page, Types::Pages::PageType - resolve -> (obj, inputs, ctx) { - page = Refinery::Page.destroy(inputs[:id]) + resolve -> (id:) { + page = Refinery::Page.destroy!(id) { page: page } } diff --git a/api/app/graph/refinery/api/mutations/pages/update.rb b/api/app/graph/refinery/api/mutations/pages/update.rb index db33db4b26..f2cecbcb07 100644 --- a/api/app/graph/refinery/api/mutations/pages/update.rb +++ b/api/app/graph/refinery/api/mutations/pages/update.rb @@ -5,7 +5,7 @@ module Api module Mutations module Pages class Update < GraphQL::Schema::Mutation - name 'UpdatePage' + graphql_name 'UpdatePage' description 'Create a page' input_field :id, !types.ID diff --git a/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb b/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb new file mode 100644 index 0000000000..eb2e643db8 --- /dev/null +++ b/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb @@ -0,0 +1,21 @@ +module Refinery + module Api + module Resolvers + module Pages + class PageResolver + class All + def self.call(obj, args, ctx) + Refinery::Page.live + end + end + + class ById + def self.call(obj, args, ctx) + Refinery::Page.find_by_id(args[:id]) + end + end + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/active_record_interface.rb b/api/app/graph/refinery/api/types/active_record_interface.rb deleted file mode 100644 index 508e44b904..0000000000 --- a/api/app/graph/refinery/api/types/active_record_interface.rb +++ /dev/null @@ -1,26 +0,0 @@ -# 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/base_enum.rb b/api/app/graph/refinery/api/types/base_enum.rb new file mode 100644 index 0000000000..0dcdc6c7d4 --- /dev/null +++ b/api/app/graph/refinery/api/types/base_enum.rb @@ -0,0 +1,8 @@ +module Refinery + module Api + module Types + class BaseEnum < GraphQL::Schema::Enum + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/base_input_object.rb b/api/app/graph/refinery/api/types/base_input_object.rb new file mode 100644 index 0000000000..3ef443f532 --- /dev/null +++ b/api/app/graph/refinery/api/types/base_input_object.rb @@ -0,0 +1,8 @@ +module Refinery + module Api + module Types + class BaseInputObject < GraphQL::Schema::InputObject + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/base_union.rb b/api/app/graph/refinery/api/types/base_union.rb new file mode 100644 index 0000000000..42fe04421d --- /dev/null +++ b/api/app/graph/refinery/api/types/base_union.rb @@ -0,0 +1,8 @@ +module Refinery + module Api + module Types + class BaseUnion < GraphQL::Schema::Union + 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 index ec22f6ba21..f61062966c 100644 --- a/api/app/graph/refinery/api/types/date_type.rb +++ b/api/app/graph/refinery/api/types/date_type.rb @@ -4,7 +4,7 @@ module Refinery module Api module Types DateType = GraphQL::ScalarType.define do - name "Date" + graphql_name "Date" description "Valid date format (parsable by Ruby's Date.parse)" coerce_input -> (value, context) do diff --git a/api/app/graph/refinery/api/types/mutation_type.rb b/api/app/graph/refinery/api/types/mutation_type.rb index 8ade6f2e31..2271cb4a8e 100644 --- a/api/app/graph/refinery/api/types/mutation_type.rb +++ b/api/app/graph/refinery/api/types/mutation_type.rb @@ -4,7 +4,7 @@ module Refinery module Api module Types class MutationType < Types::BaseObject - name 'Mutation' + graphql_name 'Mutation' description 'The mutation root for this schema' field :createPage, mutation: Mutations::Pages::Create 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 b57a23f724..4f074bb137 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 @@ -5,17 +5,15 @@ module Api module Types module Pages class PagePartType < GraphQL::Schema::Object - name "PagePart" + graphql_name "PagePart" description "A PagePart" - interfaces [Types::ActiveRecordInterface] + field :slug, String, null: true + field :position, Integer, null: true + field :title, String, null: true - field :slug, types.String - field :position, types.Int - field :title, types.String - - field :locale, types.String - field :body, types.String + field :locale, String, null: true + field :body, String, null: true end end end 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 569b6119c6..8e49209ec0 100644 --- a/api/app/graph/refinery/api/types/pages/page_type.rb +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -5,39 +5,30 @@ module Api module Types module Pages class PageType < GraphQL::Schema::Object - name "Page" + graphql_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 do - type types[Types::Pages::PagePartType] - - resolve -> (obj, args, ctx) { - obj.parts.order(:position) - } - end + field :parent_id, Integer, null: true + field :path, String, null: true + field :show_in_menu, Boolean, null: true + field :link_url, String, null: true + field :menu_match, String, null: true + field :deletable, Boolean, null: true + field :draft, Boolean, null: true + field :skip_to_first_child, Boolean, null: true + field :lft, Integer, null: true + field :rgt, Integer, null: true + field :depth, Integer, null: true + field :view_template, String, null: true + field :layout_template, String, null: true + field :locale, String, null: true + field :title, String, null: true + field :custom_slug, String, null: true + field :menu_title, String, null: true + field :slug, String, null: true + field :meta_description, String, null: true + field :browser_title, String, null: true + field :parts, [PagePartType], null: true end end end diff --git a/api/app/graph/refinery/api/types/query_type.rb b/api/app/graph/refinery/api/types/query_type.rb index 13cb7fee1d..8e193f58e6 100644 --- a/api/app/graph/refinery/api/types/query_type.rb +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -4,11 +4,19 @@ module Refinery module Api module Types class QueryType < Types::BaseObject - name 'Query' + graphql_name 'Query' description 'The query root of this schema' - field :page, field: Fields::Pages::PageField - field :pages, field: Fields::Pages::PagesField + field :pages, [Types::Pages::PageType], + null: true, resolve: Resolvers::Pages::PageResolver::All do + description "All pages" + end + + field :page, Types::Pages::PageType, + null: true, resolve: Resolvers::Pages::PageResolver::ById do + description "Find page by id" + end + end end end diff --git a/api/config/routes.rb b/api/config/routes.rb index 5118f2cad5..700384ec35 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -1,9 +1,9 @@ Refinery::Core::Engine.routes.draw do namespace :api do - post 'graphql' => 'graphql#execute' + post '/graphql', to: 'graphql#execute' if Rails.env.development? - mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/#{Refinery::Core.backend_route}/graphql" + mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: "/#{Refinery::Core.backend_route}/graphql" end end end diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb index 2942426761..48926d647f 100644 --- a/api/lib/refinery/api.rb +++ b/api/lib/refinery/api.rb @@ -1,6 +1,5 @@ require 'refinerycms-core' require 'graphql' -require 'graphiql/rails' module Refinery module Api diff --git a/api/license.md b/api/license.md index a2792fd6c8..1db26bcfc7 100644 --- a/api/license.md +++ b/api/license.md @@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2017 [Brice Sanchez](http://brice-sanchez.com) +Copyright (c) 2017 [Brice Sanchez](http://www.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 diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec index 0920c93c89..8402f0158e 100644 --- a/api/refinerycms-api.gemspec +++ b/api/refinerycms-api.gemspec @@ -20,12 +20,12 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- spec/*`.split("\n") # Runtime dependencies - s.add_dependency 'refinerycms-core', version - s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5' - s.add_dependency 'graphiql-rails', '~> 1.4' + s.add_dependency 'refinerycms-core', version + s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5' # Development dependencies (usually used for testing) s.add_development_dependency 'refinerycms-testing', '~> 4.0.0' + s.add_development_dependency 'graphiql-rails', '~> 1.4' s.required_ruby_version = Refinery::Version.required_ruby_version 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 07d811e4db..e12dd6fe7e 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 @@ -39,6 +39,7 @@ module Pages end it 'returns a page' do + byebug subject expect(result['data']['page']['title']).to eq(page.title) end From 59e6b258a73d38076a477452f71957eacfb06f99 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 5 Sep 2018 17:21:58 -0400 Subject: [PATCH 22/32] WIP: Update to GraphQL 1.8 --- .../api/fields_deprecated/pages/page_field.rb | 21 ---------- .../fields_deprecated/pages/pages_field.rb | 20 ---------- 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 ---------- .../refinery/api/mutations/pages/create.rb | 31 +++++++++------ .../refinery/api/mutations/pages/delete.rb | 22 ++++++++--- .../refinery/api/mutations/pages/update.rb | 30 +++++++++------ .../api/resolvers/pages/page_resolver.rb | 2 + api/app/graph/refinery/api/types/base_enum.rb | 2 + .../refinery/api/types/base_input_object.rb | 2 + .../refinery/api/types/base_interface.rb | 2 + .../graph/refinery/api/types/base_object.rb | 2 + .../graph/refinery/api/types/base_union.rb | 2 + .../api/types/pages/page_attributes.rb | 38 +++++++++++++++++++ .../api/types/pages/page_part_attributes.rb | 20 ++++++++++ .../graph/refinery/api/types/query_type.rb | 2 +- api/config/routes.rb | 8 ++-- api/lib/refinery/api.rb | 1 + api/refinerycms-api.gemspec | 2 +- .../pages/create_page_mutation_spec.rb | 7 ++-- .../pages/delete_page_mutation_spec.rb | 3 +- .../pages/update_page_mutation_spec.rb | 4 +- 23 files changed, 141 insertions(+), 138 deletions(-) delete mode 100644 api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb delete mode 100644 api/app/graph/refinery/api/fields_deprecated/pages/pages_field.rb delete mode 100644 api/app/graph/refinery/api/inputs/pages/page_input.rb delete mode 100644 api/app/graph/refinery/api/inputs/pages/page_part_input.rb create mode 100644 api/app/graph/refinery/api/types/pages/page_attributes.rb create mode 100644 api/app/graph/refinery/api/types/pages/page_part_attributes.rb diff --git a/api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb b/api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb deleted file mode 100644 index f756576871..0000000000 --- a/api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Fields - module Pages - class PageField < GraphQL::Schema::Field - graphql_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_deprecated/pages/pages_field.rb b/api/app/graph/refinery/api/fields_deprecated/pages/pages_field.rb deleted file mode 100644 index c047732b52..0000000000 --- a/api/app/graph/refinery/api/fields_deprecated/pages/pages_field.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Fields - module Pages - class PagesField < GraphQL::Schema::Field - graphql_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/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb index cacc028e25..ae9e76e33d 100644 --- a/api/app/graph/refinery/api/graphql_schema.rb +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -3,7 +3,7 @@ module Refinery module Api class GraphqlSchema < GraphQL::Schema - # mutation Types::MutationType + mutation Types::MutationType query Types::QueryType end end diff --git a/api/app/graph/refinery/api/inputs/pages/page_input.rb b/api/app/graph/refinery/api/inputs/pages/page_input.rb deleted file mode 100644 index 6e47e2178a..0000000000 --- a/api/app/graph/refinery/api/inputs/pages/page_input.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Inputs - module Pages - class PageInput < GraphQL::Schema::InputObject - graphql_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 deleted file mode 100644 index 73e37a0921..0000000000 --- a/api/app/graph/refinery/api/inputs/pages/page_part_input.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Inputs - module Pages - class PagePartInput < GraphQL::Schema::InputObject - graphql_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/create.rb b/api/app/graph/refinery/api/mutations/pages/create.rb index f9341d3abd..4d7d640b3d 100644 --- a/api/app/graph/refinery/api/mutations/pages/create.rb +++ b/api/app/graph/refinery/api/mutations/pages/create.rb @@ -4,21 +4,30 @@ module Refinery module Api module Mutations module Pages - class Create < GraphQL::Schema::Mutation - graphql_name 'CreatePage' - description 'Create a page' - - argument :page, !Types::Pages::PageType + class Create < Mutations::BaseMutation + null true - type Types::Pages::PageType + graphql_name 'CreatePage' + description 'Create a Page' - resolve -> (obj, inputs, ctx) { - inputs = inputs.to_h.deep_symbolize_keys + field :page, Types::Pages::PageAttributes, null: true + field :errors, [String], null: false - page = Refinery::Page.create!(inputs[:page]) + def resolve(page:) + page = Refinery::Page.create!(page) - { page: page } - } + if page.errors.empty? + { + page: page, + errors: [] + } + else + { + page: nil, + errors: page.errors.full_messages + } + end + end end end end diff --git a/api/app/graph/refinery/api/mutations/pages/delete.rb b/api/app/graph/refinery/api/mutations/pages/delete.rb index 4d80b78a30..544a6a9341 100644 --- a/api/app/graph/refinery/api/mutations/pages/delete.rb +++ b/api/app/graph/refinery/api/mutations/pages/delete.rb @@ -4,18 +4,30 @@ module Refinery module Api module Mutations module Pages - class Delete < Mutations::BaseMutation + class Delete < Mutations::BaseMutation graphql_name 'DeletePage' + description 'Delete a Page' argument :id, ID, required: true - return_field :page, Types::Pages::PageType + field :page, Types::Pages::PageType, null: false + field :errors, [String], null: false - resolve -> (id:) { + def resolve(id:) page = Refinery::Page.destroy!(id) - { page: page } - } + if page.errors.empty? + { + page: page, + errors: [] + } + else + { + page: nil, + errors: page.errors.full_messages + } + end + end end end end diff --git a/api/app/graph/refinery/api/mutations/pages/update.rb b/api/app/graph/refinery/api/mutations/pages/update.rb index f2cecbcb07..a562a7922b 100644 --- a/api/app/graph/refinery/api/mutations/pages/update.rb +++ b/api/app/graph/refinery/api/mutations/pages/update.rb @@ -4,22 +4,30 @@ module Refinery module Api module Mutations module Pages - class Update < GraphQL::Schema::Mutation + class Update < Mutations::BaseMutation graphql_name 'UpdatePage' - description 'Create a page' + description 'Update a Page' - input_field :id, !types.ID - input_field :page, !Inputs::Pages::PageInput + argument :id, ID, required: true - return_field :page, Types::Pages::PageType + field :page, Types::Pages::PageType, null: false + field :errors, [String], null: false - resolve -> (obj, inputs, ctx) { - inputs = inputs.to_h.deep_symbolize_keys + def resolve(id:, page:) + page = Refinery::Page.update(id, page) - page = Refinery::Page.update(inputs[:id], inputs[:page]) - - { page: page } - } + if page.errors.empty? + { + page: page, + errors: [] + } + else + { + page: nil, + errors: page.errors.full_messages + } + end + end end end end diff --git a/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb b/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb index eb2e643db8..00664bff12 100644 --- a/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb +++ b/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refinery module Api module Resolvers diff --git a/api/app/graph/refinery/api/types/base_enum.rb b/api/app/graph/refinery/api/types/base_enum.rb index 0dcdc6c7d4..dc22a9603a 100644 --- a/api/app/graph/refinery/api/types/base_enum.rb +++ b/api/app/graph/refinery/api/types/base_enum.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refinery module Api module Types diff --git a/api/app/graph/refinery/api/types/base_input_object.rb b/api/app/graph/refinery/api/types/base_input_object.rb index 3ef443f532..101f8e0f9d 100644 --- a/api/app/graph/refinery/api/types/base_input_object.rb +++ b/api/app/graph/refinery/api/types/base_input_object.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refinery module Api module Types diff --git a/api/app/graph/refinery/api/types/base_interface.rb b/api/app/graph/refinery/api/types/base_interface.rb index 500c20d2da..d1aab507aa 100644 --- a/api/app/graph/refinery/api/types/base_interface.rb +++ b/api/app/graph/refinery/api/types/base_interface.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refinery module Api module Types diff --git a/api/app/graph/refinery/api/types/base_object.rb b/api/app/graph/refinery/api/types/base_object.rb index 18cb6f185c..12d5d42972 100644 --- a/api/app/graph/refinery/api/types/base_object.rb +++ b/api/app/graph/refinery/api/types/base_object.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refinery module Api module Types diff --git a/api/app/graph/refinery/api/types/base_union.rb b/api/app/graph/refinery/api/types/base_union.rb index 42fe04421d..6491713e51 100644 --- a/api/app/graph/refinery/api/types/base_union.rb +++ b/api/app/graph/refinery/api/types/base_union.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refinery module Api module Types diff --git a/api/app/graph/refinery/api/types/pages/page_attributes.rb b/api/app/graph/refinery/api/types/pages/page_attributes.rb new file mode 100644 index 0000000000..1693304635 --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_attributes.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + class PageAttributes < Types::BaseInputObject + description "Attributes for creating or updating a page" + + argument :parent_id, Integer, required: false + argument :path, String, required: false + argument :show_in_menu, Boolean, required: false + argument :link_url, String, required: false + argument :menu_match, String, required: false + argument :deletable, Boolean, required: false + argument :draft, Boolean, required: false + argument :skip_to_first_child, Boolean, required: false + argument :lft, Integer, required: false + argument :rgt, required: false + argument :depth, Integer, required: false + argument :view_template, String, required: false + argument :layout_template, String, required: false + argument :locale, String, required: false + argument :title, String, required: false + argument :custom_slug, String, required: false + argument :menu_title, String, required: false + argument :slug, String, required: false + argument :meta_description, String, required: false + argument :browser_title, String, required: false + + argument :parts, [Types::PagePart], required: false + end + end + end + end +end + + diff --git a/api/app/graph/refinery/api/types/pages/page_part_attributes.rb b/api/app/graph/refinery/api/types/pages/page_part_attributes.rb new file mode 100644 index 0000000000..10e0bc7098 --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_part_attributes.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + class PagePartAttributes < Types::BaseInputObject + description "Attributes for creating or updating a page part" + + argument :slug, String, required: false + argument :position, Integer, required: false + argument :title, String, required: false + + argument :locale, String, required: false + argument :body, String, required: false + 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 8e193f58e6..5014da7802 100644 --- a/api/app/graph/refinery/api/types/query_type.rb +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -14,9 +14,9 @@ class QueryType < Types::BaseObject field :page, Types::Pages::PageType, null: true, resolve: Resolvers::Pages::PageResolver::ById do + argument :id, ID, required: true description "Find page by id" end - end end end diff --git a/api/config/routes.rb b/api/config/routes.rb index 700384ec35..cf0ca72261 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -1,9 +1,9 @@ Refinery::Core::Engine.routes.draw do namespace :api do post '/graphql', to: 'graphql#execute' + end - if Rails.env.development? - mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: "/#{Refinery::Core.backend_route}/graphql" - end + if Rails.env.development? + mount GraphiQL::Rails::Engine, at: "/#{Refinery::Core.backend_route}/api/graphiql", graphql_path: '/api/graphql' end -end +end \ No newline at end of file diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb index 48926d647f..2942426761 100644 --- a/api/lib/refinery/api.rb +++ b/api/lib/refinery/api.rb @@ -1,5 +1,6 @@ require 'refinerycms-core' require 'graphql' +require 'graphiql/rails' module Refinery module Api diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec index 8402f0158e..5f8002bcc4 100644 --- a/api/refinerycms-api.gemspec +++ b/api/refinerycms-api.gemspec @@ -22,10 +22,10 @@ Gem::Specification.new do |s| # Runtime dependencies s.add_dependency 'refinerycms-core', version s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5' + s.add_dependency 'graphiql-rails', '~> 1.4' # Development dependencies (usually used for testing) s.add_development_dependency 'refinerycms-testing', '~> 4.0.0' - s.add_development_dependency 'graphiql-rails', '~> 1.4' s.required_ruby_version = Refinery::Version.required_ruby_version 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 index 53d5723233..0ace09e606 100644 --- 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 @@ -6,7 +6,7 @@ module Refinery module Api module Mutations module Pages - describe 'CreatePageMutation' do + describe 'CreatePageMutation', focus: true do let(:logged_in_user) { Refinery::Core::NilUser.new } let(:context) { {current_user: logged_in_user} } @@ -21,8 +21,8 @@ module Pages let(:query_string) do <<-QUERY -mutation($page: CreatePageInput!) { - create_page(input: $page) { +mutation { + createPage(page: $page) { page { title } @@ -47,6 +47,7 @@ module Pages it 'returns the page title of the newly created page' do subject + byebug expect(result['data']['create_page']['page']['title']).to eq('Test page') end end diff --git a/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb index 8d91c662c2..ea5ed22947 100644 --- a/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb +++ b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb @@ -24,7 +24,7 @@ module Pages let(:query_string) do <<-QUERY mutation($page: DeletePageInput!) { - delete_page(input: $page) { + deletePage(input: $page) { page { id } @@ -39,7 +39,6 @@ module Pages 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 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 index cb6ea0b5b2..fb8cc2ec00 100644 --- 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 @@ -6,7 +6,7 @@ module Refinery module Api module Mutations module Pages - describe 'UpdatePageMutation' do + describe 'UpdatePageMutation', focus: true do let(:logged_in_user) { Refinery::Core::NilUser.new } let!(:page) { FactoryBot.create(:page) } @@ -24,7 +24,7 @@ module Pages let(:query_string) do <<-QUERY mutation($page: UpdatePageInput!) { - update_page(input: $page) { + updatePage(input: $page) { page { id title From 5aa45624aaa5ca1d88ff01c8bb9b406dbd089e98 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 5 Sep 2018 17:22:40 -0400 Subject: [PATCH 23/32] Remove focus --- .../refinery/api/mutations/pages/create_page_mutation_spec.rb | 2 +- .../refinery/api/mutations/pages/update_page_mutation_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index 0ace09e606..aa809316a1 100644 --- 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 @@ -6,7 +6,7 @@ module Refinery module Api module Mutations module Pages - describe 'CreatePageMutation', focus: true do + describe 'CreatePageMutation' do let(:logged_in_user) { Refinery::Core::NilUser.new } let(:context) { {current_user: logged_in_user} } 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 index fb8cc2ec00..26064fa0f3 100644 --- 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 @@ -6,7 +6,7 @@ module Refinery module Api module Mutations module Pages - describe 'UpdatePageMutation', focus: true do + describe 'UpdatePageMutation' do let(:logged_in_user) { Refinery::Core::NilUser.new } let!(:page) { FactoryBot.create(:page) } From b0635ee025718a63fdfbd963641e4f190da05e73 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Fri, 7 Sep 2018 07:52:55 -0400 Subject: [PATCH 24/32] Fix bugs on mutations --- .../refinery/api/graphql_controller.rb | 2 +- api/app/graph/refinery/api/types/date_type.rb | 24 ------------------- .../api/types/pages/page_attributes.rb | 4 ++-- .../refinery/api/types/pages/page_type.rb | 1 + 4 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 api/app/graph/refinery/api/types/date_type.rb diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb index a8ac6056bd..4ed40614d5 100644 --- a/api/app/controllers/refinery/api/graphql_controller.rb +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -1,6 +1,6 @@ module Refinery module Api - class GraphqlController < ApplicationController + class GraphqlController < ::ApplicationController def execute variables = ensure_hash(params[:variables]) query = params[:query] diff --git a/api/app/graph/refinery/api/types/date_type.rb b/api/app/graph/refinery/api/types/date_type.rb deleted file mode 100644 index f61062966c..0000000000 --- a/api/app/graph/refinery/api/types/date_type.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Types - DateType = GraphQL::ScalarType.define do - graphql_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/pages/page_attributes.rb b/api/app/graph/refinery/api/types/pages/page_attributes.rb index 1693304635..c4ecf93426 100644 --- a/api/app/graph/refinery/api/types/pages/page_attributes.rb +++ b/api/app/graph/refinery/api/types/pages/page_attributes.rb @@ -16,7 +16,7 @@ class PageAttributes < Types::BaseInputObject argument :draft, Boolean, required: false argument :skip_to_first_child, Boolean, required: false argument :lft, Integer, required: false - argument :rgt, required: false + argument :rgt, Integer, required: false argument :depth, Integer, required: false argument :view_template, String, required: false argument :layout_template, String, required: false @@ -28,7 +28,7 @@ class PageAttributes < Types::BaseInputObject argument :meta_description, String, required: false argument :browser_title, String, required: false - argument :parts, [Types::PagePart], required: false + argument :parts, [PagePartAttributes], required: false end end end 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 8e49209ec0..c0e37b1d70 100644 --- a/api/app/graph/refinery/api/types/pages/page_type.rb +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -28,6 +28,7 @@ class PageType < GraphQL::Schema::Object field :slug, String, null: true field :meta_description, String, null: true field :browser_title, String, null: true + field :parts, [PagePartType], null: true end end From e55a47111fb4918bc4f815006a7095ae7bf00ace Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Fri, 7 Sep 2018 08:09:52 -0400 Subject: [PATCH 25/32] Remove forgotten byebug --- api/spec/graph/refinery/api/fields/pages/page_field_spec.rb | 1 - .../refinery/api/mutations/pages/create_page_mutation_spec.rb | 1 - 2 files changed, 2 deletions(-) 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 e12dd6fe7e..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 @@ -39,7 +39,6 @@ module Pages end it 'returns a page' do - byebug subject expect(result['data']['page']['title']).to eq(page.title) end 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 index aa809316a1..feac667138 100644 --- 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 @@ -47,7 +47,6 @@ module Pages it 'returns the page title of the newly created page' do subject - byebug expect(result['data']['create_page']['page']['title']).to eq('Test page') end end From 7dee17a268bc2bf0a2c1df41bf4c07ca777a5e25 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 11 Sep 2018 23:41:48 -0400 Subject: [PATCH 26/32] Fix mutations for 1.8 --- .../refinery/api/mutations/pages/create.rb | 8 ++--- .../refinery/api/mutations/pages/delete.rb | 4 +-- .../refinery/api/mutations/pages/update.rb | 3 +- .../refinery/api/types/pages/page_type.rb | 1 + .../pages/create_page_mutation_spec.rb | 24 +++++++-------- .../pages/delete_page_mutation_spec.rb | 25 ++++++++++------ .../pages/update_page_mutation_spec.rb | 30 +++++++++---------- 7 files changed, 52 insertions(+), 43 deletions(-) diff --git a/api/app/graph/refinery/api/mutations/pages/create.rb b/api/app/graph/refinery/api/mutations/pages/create.rb index 4d7d640b3d..37dd7fe5bd 100644 --- a/api/app/graph/refinery/api/mutations/pages/create.rb +++ b/api/app/graph/refinery/api/mutations/pages/create.rb @@ -5,16 +5,16 @@ module Api module Mutations module Pages class Create < Mutations::BaseMutation - null true - graphql_name 'CreatePage' description 'Create a Page' - field :page, Types::Pages::PageAttributes, null: true + argument :page, Types::Pages::PageAttributes, required: true + + field :page, Types::Pages::PageType, null: true field :errors, [String], null: false def resolve(page:) - page = Refinery::Page.create!(page) + page = Refinery::Page.create!(page.to_h) if page.errors.empty? { diff --git a/api/app/graph/refinery/api/mutations/pages/delete.rb b/api/app/graph/refinery/api/mutations/pages/delete.rb index 544a6a9341..1a9aeb052d 100644 --- a/api/app/graph/refinery/api/mutations/pages/delete.rb +++ b/api/app/graph/refinery/api/mutations/pages/delete.rb @@ -10,11 +10,11 @@ class Delete < Mutations::BaseMutation argument :id, ID, required: true - field :page, Types::Pages::PageType, null: false + field :page, Types::Pages::PageType, null: true field :errors, [String], null: false def resolve(id:) - page = Refinery::Page.destroy!(id) + page = Refinery::Page.destroy(id) if page.errors.empty? { diff --git a/api/app/graph/refinery/api/mutations/pages/update.rb b/api/app/graph/refinery/api/mutations/pages/update.rb index a562a7922b..2fa9685853 100644 --- a/api/app/graph/refinery/api/mutations/pages/update.rb +++ b/api/app/graph/refinery/api/mutations/pages/update.rb @@ -9,12 +9,13 @@ class Update < Mutations::BaseMutation description 'Update a Page' argument :id, ID, required: true + argument :page, Types::Pages::PageAttributes, required: true field :page, Types::Pages::PageType, null: false field :errors, [String], null: false def resolve(id:, page:) - page = Refinery::Page.update(id, page) + page = Refinery::Page.update(id, page.to_h) if page.errors.empty? { 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 c0e37b1d70..e698702383 100644 --- a/api/app/graph/refinery/api/types/pages/page_type.rb +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -8,6 +8,7 @@ class PageType < GraphQL::Schema::Object graphql_name "Page" description "A Page" + field :id, Integer, null: false field :parent_id, Integer, null: true field :path, String, null: true field :show_in_menu, Boolean, null: true 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 index feac667138..249a87e9a6 100644 --- 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 @@ -20,14 +20,14 @@ module Pages end let(:query_string) do - <<-QUERY -mutation { - createPage(page: $page) { - page { - title - } - } -} + <<~QUERY + mutation createPage($input: CreatePageInput!) { + createPage(input: $input) { + page { + title + } + } + } QUERY end @@ -37,9 +37,9 @@ module Pages context 'create a page' do let(:variables) do { - 'page' => { - 'page' => { - 'title' => 'Test page' + "input": { + "page": { + "title": "Test page" } } } @@ -47,7 +47,7 @@ module Pages it 'returns the page title of the newly created page' do subject - expect(result['data']['create_page']['page']['title']).to eq('Test page') + expect(result['data']['createPage']['page']['title']).to eq('Test page') end end end diff --git a/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb index ea5ed22947..f048c60686 100644 --- a/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb +++ b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb @@ -22,23 +22,30 @@ module Pages end let(:query_string) do - <<-QUERY -mutation($page: DeletePageInput!) { - deletePage(input: $page) { - page { - id - } - } -} + <<~QUERY + mutation deletePage($input: DeletePageInput!) { + deletePage(input: $input) { + page { + id + } + } + } QUERY end subject { result } context 'Correct page id' do - let(:variables) { {'page' => { 'id' => page.id }} } + let(:variables) do + { + "input": { + "id": page.id + } + } + end it 'deletes the page' do + subject expect(Refinery::Page.find_by_id(page.id)).to be(nil) end end 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 index 26064fa0f3..3f2b175326 100644 --- 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 @@ -22,15 +22,15 @@ module Pages end let(:query_string) do - <<-QUERY -mutation($page: UpdatePageInput!) { - updatePage(input: $page) { - page { - id - title - } - } -} + <<~QUERY + mutation updatePage($input: UpdatePageInput!) { + updatePage(input: $input) { + page { + id + title + } + } + } QUERY end @@ -40,10 +40,10 @@ module Pages context 'update a page' do let(:variables) do { - 'page' => { - 'id' => page.id, - 'page' => { - 'title' => 'Updated Test page' + "input": { + "id": page.id, + "page": { + "title": "Updated test page" } } } @@ -51,8 +51,8 @@ module Pages 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') + expect(result['data']['updatePage']['page']['id']).to eq(page.id) + expect(result['data']['updatePage']['page']['title']).to eq('Updated test page') end end end From 29b6310b83e6277d544a36d47bb1b264a857569f Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 12 Sep 2018 08:08:18 -0400 Subject: [PATCH 27/32] Fix specs old ruby versions --- .../refinery/api/fields/pages/page_field_spec.rb | 14 +++++++------- .../refinery/api/fields/pages/pages_field_spec.rb | 14 +++++++------- .../mutations/pages/create_page_mutation_spec.rb | 4 ++-- .../mutations/pages/delete_page_mutation_spec.rb | 4 ++-- .../mutations/pages/update_page_mutation_spec.rb | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) 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 07d811e4db..e4519ccc8f 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 @@ -22,13 +22,13 @@ module Pages end let(:query_string) do - <<-QUERY -query($id: ID!) { - page(id: $id) { - title - } -} - QUERY + <<-GRAPHQL + query($id: ID!) { + page(id: $id) { + title + } + } + GRAPHQL end subject { result } 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 dfb8a8db4b..83999c2c51 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 @@ -22,13 +22,13 @@ module Pages end let(:query_string) do - <<-QUERY -query { - pages { - title - } -} - QUERY + <<-GRAPHQL + query { + pages { + title + } + } + GRAPHQL end subject { result } 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 index 249a87e9a6..6153518482 100644 --- 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 @@ -20,7 +20,7 @@ module Pages end let(:query_string) do - <<~QUERY + <<-GRAPHQL mutation createPage($input: CreatePageInput!) { createPage(input: $input) { page { @@ -28,7 +28,7 @@ module Pages } } } - QUERY + GRAPHQL end subject { result } diff --git a/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb index f048c60686..5751d6efe0 100644 --- a/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb +++ b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb @@ -22,7 +22,7 @@ module Pages end let(:query_string) do - <<~QUERY + <<-GRAPHQL mutation deletePage($input: DeletePageInput!) { deletePage(input: $input) { page { @@ -30,7 +30,7 @@ module Pages } } } - QUERY + GRAPHQL end subject { result } 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 index 3f2b175326..40e37833f8 100644 --- 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 @@ -22,7 +22,7 @@ module Pages end let(:query_string) do - <<~QUERY + <<-GRAPHQL mutation updatePage($input: UpdatePageInput!) { updatePage(input: $input) { page { @@ -31,7 +31,7 @@ module Pages } } } - QUERY + GRAPHQL end subject { result } From ae6452bf0a76107a2389b15b98c6a1046e2da247 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 18 Sep 2018 17:27:50 -0400 Subject: [PATCH 28/32] WIP: Add authorization to the API --- .../refinery/api/graphql_controller.rb | 2 ++ api/app/graph/refinery/api/graphql_schema.rb | 1 + .../refinery/api/mutations/pages/create.rb | 2 ++ .../refinery/api/mutations/pages/delete.rb | 2 ++ .../refinery/api/mutations/pages/update.rb | 2 ++ .../refinery/api/queries/pages/page_query.rb | 30 +++++++++++++++++++ .../refinery/api/queries/pages/pages_query.rb | 0 .../api/resolvers/pages/page_resolver.rb | 16 +++++++--- .../graph/refinery/api/types/query_type.rb | 24 +++++++++------ api/lib/refinery/api.rb | 1 + api/refinerycms-api.gemspec | 1 + .../api/fields/pages/page_field_spec.rb | 13 +++++++- 12 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 api/app/graph/refinery/api/queries/pages/page_query.rb create mode 100644 api/app/graph/refinery/api/queries/pages/pages_query.rb diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb index 4ed40614d5..2b5da9a3f3 100644 --- a/api/app/controllers/refinery/api/graphql_controller.rb +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -1,6 +1,8 @@ module Refinery module Api class GraphqlController < ::ApplicationController + include Refinery::Admin::BaseController + def execute variables = ensure_hash(params[:variables]) query = params[:query] diff --git a/api/app/graph/refinery/api/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb index ae9e76e33d..fdbf27c5e8 100644 --- a/api/app/graph/refinery/api/graphql_schema.rb +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -5,6 +5,7 @@ module Api class GraphqlSchema < GraphQL::Schema mutation Types::MutationType query Types::QueryType + use GraphQL::Guard.new end end end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/create.rb b/api/app/graph/refinery/api/mutations/pages/create.rb index 37dd7fe5bd..701bced284 100644 --- a/api/app/graph/refinery/api/mutations/pages/create.rb +++ b/api/app/graph/refinery/api/mutations/pages/create.rb @@ -8,6 +8,8 @@ class Create < Mutations::BaseMutation graphql_name 'CreatePage' description 'Create a Page' + guard ->(_obj, _args, ctx) { ctx[:current_user].has_role?(:refinery) } + argument :page, Types::Pages::PageAttributes, required: true field :page, Types::Pages::PageType, null: true diff --git a/api/app/graph/refinery/api/mutations/pages/delete.rb b/api/app/graph/refinery/api/mutations/pages/delete.rb index 1a9aeb052d..62a86f0e62 100644 --- a/api/app/graph/refinery/api/mutations/pages/delete.rb +++ b/api/app/graph/refinery/api/mutations/pages/delete.rb @@ -8,6 +8,8 @@ class Delete < Mutations::BaseMutation graphql_name 'DeletePage' description 'Delete a Page' + guard ->(_obj, _args, ctx) { ctx[:current_user].has_role?(:refinery) } + argument :id, ID, required: true field :page, Types::Pages::PageType, null: true diff --git a/api/app/graph/refinery/api/mutations/pages/update.rb b/api/app/graph/refinery/api/mutations/pages/update.rb index 2fa9685853..66d9931644 100644 --- a/api/app/graph/refinery/api/mutations/pages/update.rb +++ b/api/app/graph/refinery/api/mutations/pages/update.rb @@ -8,6 +8,8 @@ class Update < Mutations::BaseMutation graphql_name 'UpdatePage' description 'Update a Page' + guard ->(_obj, _args, ctx) { ctx[:current_user].has_role?(:refinery) } + argument :id, ID, required: true argument :page, Types::Pages::PageAttributes, required: true diff --git a/api/app/graph/refinery/api/queries/pages/page_query.rb b/api/app/graph/refinery/api/queries/pages/page_query.rb new file mode 100644 index 0000000000..c072acba6d --- /dev/null +++ b/api/app/graph/refinery/api/queries/pages/page_query.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Queries + module Pages + class PageQuery < 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 + +# frozen_string_literal: true + +field :page, Types::Pages::PageType, + null: true, resolve: Resolvers::Pages::PageResolver::ById do + description "Find page by id" + guard ->(_obj, _args, ctx) { ctx[:current_user].has_plugin?('refinery_pages') } + argument :id, ID, required: true + end \ No newline at end of file diff --git a/api/app/graph/refinery/api/queries/pages/pages_query.rb b/api/app/graph/refinery/api/queries/pages/pages_query.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb b/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb index 00664bff12..1cb282d383 100644 --- a/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb +++ b/api/app/graph/refinery/api/resolvers/pages/page_resolver.rb @@ -6,14 +6,22 @@ module Resolvers module Pages class PageResolver class All - def self.call(obj, args, ctx) - Refinery::Page.live + def self.call(_obj, args, ctx) + if ctx[:current_user].has_role?(:refinery) + Refinery::Page.all + else + Refinery::Page.live + end end end class ById - def self.call(obj, args, ctx) - Refinery::Page.find_by_id(args[:id]) + def self.call(_obj, args, ctx) + if ctx[:current_user].has_role?(:refinery) + Refinery::Page.find_by_id(args[:id]) + else + Refinery::Page.live.find_by_id(args[:id]) + end end end end diff --git a/api/app/graph/refinery/api/types/query_type.rb b/api/app/graph/refinery/api/types/query_type.rb index 5014da7802..b12b0b5fe1 100644 --- a/api/app/graph/refinery/api/types/query_type.rb +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -7,16 +7,22 @@ class QueryType < Types::BaseObject graphql_name 'Query' description 'The query root of this schema' - field :pages, [Types::Pages::PageType], - null: true, resolve: Resolvers::Pages::PageResolver::All do - description "All pages" - end + # field :pages, [Types::Pages::PageType], + # null: true, resolve: Resolvers::Pages::PageResolver::All do + # description "All pages" + # guard ->(_obj, _args, ctx) { ctx[:current_user].has_plugin?('refinery_pages') } + # end - field :page, Types::Pages::PageType, - null: true, resolve: Resolvers::Pages::PageResolver::ById do - argument :id, ID, required: true - description "Find page by id" - end + field :page, field: Queries::Pages::PageQuery + field :pages, field: Queries::Pages::PagesQuery + + + # field :page, Types::Pages::PageType, + # null: true, resolve: Resolvers::Pages::PageResolver::ById do + # description "Find page by id" + # guard ->(_obj, _args, ctx) { ctx[:current_user].has_plugin?('refinery_pages') } + # argument :id, ID, required: true + # end end end end diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb index 2942426761..dfe4775fc2 100644 --- a/api/lib/refinery/api.rb +++ b/api/lib/refinery/api.rb @@ -1,5 +1,6 @@ require 'refinerycms-core' require 'graphql' +require 'graphql/guard' require 'graphiql/rails' module Refinery diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec index 5f8002bcc4..81bcc073f9 100644 --- a/api/refinerycms-api.gemspec +++ b/api/refinerycms-api.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |s| # Runtime dependencies s.add_dependency 'refinerycms-core', version s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5' + s.add_dependency 'graphql-guard', '~> 1.2' s.add_dependency 'graphiql-rails', '~> 1.4' # Development dependencies (usually used for testing) 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 e4519ccc8f..4b85c3f197 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 @@ -33,7 +33,18 @@ module Pages subject { result } - context "as a normal user" do + context "as a visitor" do + let(:variables) do + {'query' => '', 'id' => page.id } + end + + it 'returns a page' do + subject + expect(result['data']['page']['title']).to eq(page.title) + end + end + + context "as an admin user" do let(:variables) do {'query' => '', 'id' => page.id } end From 9e7e88f887c8435ff068c34fde3f74256312ceb3 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 17 Dec 2019 22:03:06 -0500 Subject: [PATCH 29/32] Remove graphiql-rails --- api/refinerycms-api.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec index 81bcc073f9..a9cffb7299 100644 --- a/api/refinerycms-api.gemspec +++ b/api/refinerycms-api.gemspec @@ -23,7 +23,6 @@ Gem::Specification.new do |s| s.add_dependency 'refinerycms-core', version s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5' s.add_dependency 'graphql-guard', '~> 1.2' - s.add_dependency 'graphiql-rails', '~> 1.4' # Development dependencies (usually used for testing) s.add_development_dependency 'refinerycms-testing', '~> 4.0.0' From 5a7f64740e20d523202d192223f91fab26da77c2 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 17 Dec 2019 22:03:24 -0500 Subject: [PATCH 30/32] Update graphql gem to 1.9.17 --- 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 a9cffb7299..ed24df5b9b 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.8', '>= 1.8.5' + s.add_dependency 'graphql', '~> 1.9', '>= 1.9.17' s.add_dependency 'graphql-guard', '~> 1.2' # Development dependencies (usually used for testing) From be07589656d409f9d97bfdfda72bdbcfb483a2c0 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 17 Dec 2019 23:02:44 -0500 Subject: [PATCH 31/32] Remove GraphiQL requires and routes --- api/config/routes.rb | 6 +----- api/lib/refinery/api.rb | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/api/config/routes.rb b/api/config/routes.rb index cf0ca72261..a89ba509b3 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -2,8 +2,4 @@ namespace :api do post '/graphql', to: 'graphql#execute' end - - if Rails.env.development? - mount GraphiQL::Rails::Engine, at: "/#{Refinery::Core.backend_route}/api/graphiql", graphql_path: '/api/graphql' - end -end \ No newline at end of file +end diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb index dfe4775fc2..98439f4a25 100644 --- a/api/lib/refinery/api.rb +++ b/api/lib/refinery/api.rb @@ -1,7 +1,6 @@ require 'refinerycms-core' require 'graphql' require 'graphql/guard' -require 'graphiql/rails' module Refinery module Api From 2f6e2f510bf8e3380808028397d784893ed6e693 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 17 Dec 2019 23:03:09 -0500 Subject: [PATCH 32/32] Move graphql api route to /api/graphql --- api/config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/config/routes.rb b/api/config/routes.rb index a89ba509b3..91c120ba14 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -1,5 +1,5 @@ Refinery::Core::Engine.routes.draw do namespace :api do - post '/graphql', to: 'graphql#execute' + post '/api/graphql', to: 'graphql#execute' end end