Skip to content

Commit

Permalink
chore(gql): monkey compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcadiz committed Jan 11, 2021
1 parent e009a76 commit 5840873
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
8 changes: 6 additions & 2 deletions lib/potassium/recipes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def add_graphql
gsub_file 'app/graphql/mutations/base_mutation.rb', 'Types::Base', 'Types::Base::Base'
directory '../assets/app/graphql/queries', 'app/graphql/queries'
gsub_file 'app/graphql/mutations/base_mutation.rb', 'RelayClassic', ''
gsub_file 'app/graphql/mutations/base_mutation.rb', " input_object_class Types::Base::BaseInputObject\n", ''
gsub_file(
'app/graphql/mutations/base_mutation.rb',
" input_object_class Types::Base::BaseInputObject\n", ''
)

if get(:authentication)
copy_file(
Expand All @@ -91,7 +94,8 @@ def add_graphql
'../assets/app/graphql/mutations/login_mutation.rb',
'app/graphql/mutations/login_mutation.rb'
)
inject_into_file('app/graphql/types/mutation_type.rb',
inject_into_file(
'app/graphql/types/mutation_type.rb',
"\n field :login, mutation: Mutations::LoginMutation",
after: 'class MutationType < Types::Base::BaseObject'
)
Expand Down
24 changes: 15 additions & 9 deletions spec/features/graphql_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "spec_helper"

RSpec.describe "Api" do

RSpec.describe "GraphQL" do
context 'when using only graphql' do
before :all do
drop_dummy_database
Expand All @@ -17,21 +16,27 @@
end

it 'installs and sets up graphql' do
schema = IO.read("#{project_path}/app/graphql/#{PotassiumTestHelpers::APP_NAME.dasherize.gsub('-','_')}_schema.rb")
expect(schema).to include("class #{PotassiumTestHelpers::APP_NAME.titleize.delete(' ')}Schema < GraphQL::Schema")
schema = IO.read(
"#{project_path}/app/graphql/#{PotassiumTestHelpers::APP_NAME.dasherize.tr('-', '_')}_schema.rb"
)
expect(schema).to include(
"class #{PotassiumTestHelpers::APP_NAME.titleize.delete(' ')}Schema < GraphQL::Schema"
)

base_mutation = IO.read("#{project_path}/app/graphql/mutations/base_mutation.rb")
expect(base_mutation).to include('Types::Base::Base')
expect(base_mutation).not_to include('input_object_class')
expect(base_mutation).not_to include('RelayClassic')

controller = base_mutation = IO.read("#{project_path}/app/controllers/graphql_controller.rb")
controller = IO.read("#{project_path}/app/controllers/graphql_controller.rb")
expect(controller).to include('skip_before_action :verify_authenticity_token')
end

it 'sets up graphql playground' do
routes = IO.read("#{project_path}/config/routes.rb")
expect(routes).to include('mount GraphqlPlayground::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"')
expect(routes).to include(
'mount GraphqlPlayground::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"'
)
config = IO.read("#{project_path}/config/initializers/graphql_playground.rb")
expect(config).to include('GraphqlPlayground::Rails.configure do |config|')
end
Expand All @@ -50,9 +55,11 @@
end

it 'Adds auth related mutation and controller' do
controller = base_mutation = IO.read("#{project_path}/app/controllers/graphql_controller.rb")
controller = IO.read("#{project_path}/app/controllers/graphql_controller.rb")
expect(controller).to include('get_current_user')
expect(controller).to include("#{PotassiumTestHelpers::APP_NAME.titleize.delete(' ')}Schema.execute")
expect(controller).to include(
"#{PotassiumTestHelpers::APP_NAME.titleize.delete(' ')}Schema.execute"
)

mutation_type = IO.read("#{project_path}/app/graphql/types/mutation_type.rb")
expect(mutation_type).to include('field :login, mutation: Mutations::LoginMutation')
Expand All @@ -61,5 +68,4 @@
expect(login_mutation).to include('class Mutations::LoginMutation < Mutations::BaseMutation')
end
end

end

0 comments on commit 5840873

Please sign in to comment.