Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1956 from Shopify/jb/fetch-plans-input-query
Browse files Browse the repository at this point in the history
Send `input.graphql` to script service
  • Loading branch information
jbourassa authored Jan 28, 2022
2 parents 47fb451 + d0d92ea commit f96ac5d
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 40 deletions.
2 changes: 2 additions & 0 deletions lib/project_types/script/graphql/app_script_set.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mutation AppScriptSet(
$configurationDefinition: String!,
$moduleUploadUrl: String!,
$library: LibraryInput,
$inputQuery: String,
) {
appScriptSet(
uuid: $uuid
Expand All @@ -25,6 +26,7 @@ mutation AppScriptSet(
configurationDefinition: $configurationDefinition,
moduleUploadUrl: $moduleUploadUrl,
library: $library,
inputQuery: $inputQuery,
) {
userErrors {
field
Expand Down
1 change: 1 addition & 0 deletions lib/project_types/script/layers/application/push_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def call(ctx:, force:, project:)
script_config: package.script_config,
module_upload_url: module_upload_url,
library: package.library,
input_query: script_project.input_query,
)
if ShopifyCLI::Environment.interactive?
script_project_repo.update_env(uuid: uuid)
Expand Down
1 change: 1 addition & 0 deletions lib/project_types/script/layers/domain/script_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ScriptProject
property! :language, accepts: String

property :script_config, accepts: ScriptConfig
property :input_query, accepts: String

def initialize(*)
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ScriptProjectRepository
property :initial_directory, accepts: String

MUTABLE_ENV_VALUES = %i(uuid)
INPUT_QUERY_PATH = "input.graphql"

def create_project_directory
raise Infrastructure::Errors::ScriptProjectAlreadyExistsError, directory if ctx.dir_exist?(directory)
Expand Down Expand Up @@ -38,13 +39,7 @@ def create(script_name:, extension_point_type:, language:)
language: language
)

Domain::ScriptProject.new(
id: ctx.root,
env: project.env,
script_name: script_name,
extension_point_type: extension_point_type,
language: language
)
build_script_project(script_config: nil)
end

def get
Expand All @@ -56,7 +51,8 @@ def get
script_name: script_name,
extension_point_type: extension_point_type,
language: language,
script_config: script_config_repository.get!
script_config: script_config_repository.get!,
input_query: read_input_query,
)
end

Expand All @@ -68,14 +64,7 @@ def update_env(**args)
end
end

Domain::ScriptProject.new(
id: ctx.root,
env: project.env,
script_name: script_name,
extension_point_type: extension_point_type,
language: language,
script_config: script_config_repository.get!,
)
build_script_project
end

def create_env(api_key:, secret:, uuid:)
Expand All @@ -87,19 +76,19 @@ def create_env(api_key:, secret:, uuid:)
}
).write(ctx)

Domain::ScriptProject.new(
id: ctx.root,
env: project.env,
script_name: script_name,
extension_point_type: extension_point_type,
language: language,
script_config: script_config_repository.get!,
)
build_script_project
end

def update_script_config(title:)
script_config = script_config_repository.update!(title: title)
build_script_project(script_config: script_config)
end

private

def build_script_project(
script_config: script_config_repository.get!
)
Domain::ScriptProject.new(
id: ctx.root,
env: project.env,
Expand All @@ -110,8 +99,6 @@ def update_script_config(title:)
)
end

private

def change_directory(directory:)
ctx.chdir(directory)
end
Expand Down Expand Up @@ -173,6 +160,10 @@ def script_config_repository
end
end

def read_input_query
ctx.read(INPUT_QUERY_PATH) if ctx.file_exist?(INPUT_QUERY_PATH)
end

class ScriptConfigRepository
include SmartProperties
property! :ctx, accepts: ShopifyCLI::Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def set_app_script(
metadata:,
script_config:,
module_upload_url:,
library:
library:,
input_query: nil
)
query_name = "app_script_set"
variables = {
Expand All @@ -38,6 +39,7 @@ def set_app_script(
language: library[:language],
version: library[:version],
},
inputQuery: input_query,
}
resp_hash = make_request(query_name: query_name, variables: variables)
user_errors = resp_hash["data"]["appScriptSet"]["userErrors"]
Expand Down
16 changes: 10 additions & 6 deletions test/project_types/script/layers/application/push_script_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
end
let(:schema_minor_version) { "0" }
let(:script_name) { "name" }
let(:input_query) { "{ aField }" }
let(:script_project) do
script_project_repository.create(
language: library_language,
extension_point_type: extension_point_type,
script_name: script_name,
env: ShopifyCLI::Resources::EnvFile.new(api_key: api_key, secret: "shh")
env: ShopifyCLI::Resources::EnvFile.new(api_key: api_key, secret: "shh"),
input_query: input_query,
)
end
let(:push_package_repository) { TestHelpers::FakePushPackageRepository.new }
Expand Down Expand Up @@ -61,14 +63,16 @@

it "should prepare and push script" do
script_service_instance = mock
script_service_instance.expects(:set_app_script).returns(uuid)
script_service_instance
.expects(:set_app_script)
.with do |params|
assert_equal "{ aField }", params.fetch(:input_query)
end
.returns(uuid)
Script::Layers::Infrastructure::ScriptService
.expects(:new).returns(script_service_instance)

script_uploader_instance = mock
script_uploader_instance.expects(:upload).returns(url)
Script::Layers::Infrastructure::ScriptUploader
.expects(:new).returns(script_uploader_instance)
Script::Layers::Infrastructure::ScriptUploader.expects(new: mock(upload: url))

Script::Layers::Application::ProjectDependencies
.expects(:install).with(ctx: @context, task_runner: task_runner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"title" => script_name,
}
end
let(:input_query) { "{ aField }" }

describe ".new" do
subject { Script::Layers::Domain::ScriptProject.new(**args) }
Expand All @@ -33,6 +34,7 @@
script_name: script_name,
language: language,
script_config: script_config,
input_query: input_query,
}
end
let(:args) { all_args }
Expand All @@ -54,6 +56,7 @@
assert_equal script_name, subject.script_name
assert_equal language, subject.language
assert_equal script_config, subject.script_config
assert_equal input_query, subject.input_query
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
let(:ctx) { TestHelpers::FakeContext.new }
let(:instance) do
Script::Layers::Infrastructure::ScriptProjectRepository.new(
ctx: ctx,
directory: directory,
initial_directory: ctx.root
)
ctx: ctx,
directory: directory,
initial_directory: ctx.root
)
end

let(:deprecated_ep_types) { [] }
Expand Down Expand Up @@ -115,11 +115,13 @@ def it_should_create_a_new_script_project
let(:current_project) do
TestHelpers::FakeProject.new(directory: File.join(ctx.root, script_name), config: actual_config)
end
let(:input_query) { nil }

before do
ShopifyCLI::Project.stubs(:has_current?).returns(true)
ShopifyCLI::Project.stubs(:current).returns(current_project)
ctx.write(script_config, script_config_content.to_json)
ctx.write("input.graphql", input_query) if input_query
end

describe "when project config is valid" do
Expand Down Expand Up @@ -153,6 +155,14 @@ def it_should_create_a_new_script_project
assert_equal script_config_content["version"], subject.script_config.version
assert_equal script_config_content["version"], subject.script_config.version
assert_equal script_config_content["configuration"].to_json, subject.script_config.configuration.to_json
assert_nil subject.input_query
end

describe "when input.graphql file is present" do
let(:input_query) { "{ aField }" }
it "populates the input_query field" do
assert_equal input_query, subject.input_query
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
}
end

it "should post the form without scope" do
it "returns the script's uuid" do
assert_equal(uuid_from_server, subject)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(
@project = nil
end

def create(script_name:, extension_point_type:, language:, env: nil)
def create(script_name:, extension_point_type:, language:, env: nil, input_query: nil)
script_config = fake_script_config_repo.create({ "version" => 1, "title" => script_name })

@project = Script::Layers::Domain::ScriptProject.new(
Expand All @@ -24,7 +24,8 @@ def create(script_name:, extension_point_type:, language:, env: nil)
script_name: script_name,
extension_point_type: extension_point_type,
language: language,
script_config: script_config
script_config: script_config,
input_query: input_query,
)
end

Expand Down

0 comments on commit f96ac5d

Please sign in to comment.