Skip to content
Snippets Groups Projects
Commit e2518f00 authored by Miguel Rincon's avatar Miguel Rincon
Browse files

Remove get_graphql_query_as_string fragment_paths

This change simplifies the usage of get_graphql_query_as_string by
removing the required fragment_paths from it.
parent 0e7aa6fc
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -891,14 +891,13 @@ describe GraphQL::Query, type: :request do
include GraphqlHelpers
 
all_releases_query_path = 'releases/graphql/queries/all_releases.query.graphql'
fragment_paths = ['releases/graphql/fragments/release.fragment.graphql']
 
before(:all) do
clean_frontend_fixtures('graphql/releases/')
end
 
it "graphql/#{all_releases_query_path}.json" do
query = get_graphql_query_as_string(all_releases_query_path, fragment_paths)
query = get_graphql_query_as_string(all_releases_query_path)
 
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path })
 
Loading
Loading
@@ -910,10 +909,6 @@ end
This will create a new fixture located at
`tmp/tests/frontend/fixtures-ee/graphql/releases/graphql/queries/all_releases.query.graphql.json`.
 
You will need to provide the paths to all fragments used by the query.
`get_graphql_query_as_string` reads all of the provided file paths and returns
the result as a single, concatenated string.
You can import the JSON fixture in a Jest test using the `getJSONFixture` method
[as described below](#use-fixtures).
 
Loading
Loading
Loading
Loading
@@ -61,13 +61,12 @@
clean_frontend_fixtures('graphql/projects/access_tokens')
end
 
fragment_paths = ['graphql_shared/fragments/pageInfo.fragment.graphql']
base_input_path = 'access_tokens/graphql/queries/'
base_output_path = 'graphql/projects/access_tokens/'
query_name = 'get_projects.query.graphql'
 
it "#{base_output_path}#{query_name}.json" do
query = get_graphql_query_as_string("#{base_input_path}#{query_name}", fragment_paths)
query = get_graphql_query_as_string("#{base_input_path}#{query_name}")
 
post_graphql(query, current_user: user, variables: { search: '', first: 2 })
 
Loading
Loading
Loading
Loading
@@ -133,15 +133,13 @@
all_releases_query_path = 'releases/graphql/queries/all_releases.query.graphql'
one_release_query_path = 'releases/graphql/queries/one_release.query.graphql'
one_release_for_editing_query_path = 'releases/graphql/queries/one_release_for_editing.query.graphql'
release_fragment_path = 'releases/graphql/fragments/release.fragment.graphql'
release_for_editing_fragment_path = 'releases/graphql/fragments/release_for_editing.fragment.graphql'
 
before(:all) do
clean_frontend_fixtures('graphql/releases/')
end
 
it "graphql/#{all_releases_query_path}.json" do
query = get_graphql_query_as_string(all_releases_query_path, [release_fragment_path])
query = get_graphql_query_as_string(all_releases_query_path)
 
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path })
 
Loading
Loading
@@ -150,7 +148,7 @@
end
 
it "graphql/#{one_release_query_path}.json" do
query = get_graphql_query_as_string(one_release_query_path, [release_fragment_path])
query = get_graphql_query_as_string(one_release_query_path)
 
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path, tagName: release.tag })
 
Loading
Loading
@@ -159,7 +157,7 @@
end
 
it "graphql/#{one_release_for_editing_query_path}.json" do
query = get_graphql_query_as_string(one_release_for_editing_query_path, [release_for_editing_fragment_path])
query = get_graphql_query_as_string(one_release_for_editing_query_path)
 
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path, tagName: release.tag })
 
Loading
Loading
Loading
Loading
@@ -36,10 +36,7 @@
get_runners_query_name = 'get_runners.query.graphql'
 
let_it_be(:query) do
get_graphql_query_as_string("#{query_path}#{get_runners_query_name}", [
'runner/graphql/runner_node.fragment.graphql',
'graphql_shared/fragments/pageInfo.fragment.graphql'
])
get_graphql_query_as_string("#{query_path}#{get_runners_query_name}")
end
 
it "#{fixtures_path}#{get_runners_query_name}.json" do
Loading
Loading
@@ -59,9 +56,7 @@
get_runner_query_name = 'get_runner.query.graphql'
 
let_it_be(:query) do
get_graphql_query_as_string("#{query_path}#{get_runner_query_name}", [
'runner/graphql/runner_details.fragment.graphql'
])
get_graphql_query_as_string("#{query_path}#{get_runner_query_name}")
end
 
it "#{fixtures_path}#{get_runner_query_name}.json" do
Loading
Loading
Loading
Loading
@@ -43,12 +43,14 @@ def remove_repository(project)
# Public: Reads a GraphQL query from the filesystem as a string
#
# query_path - file path to the GraphQL query, relative to `app/assets/javascripts`
# fragment_paths - an optional array of file paths to any fragments the query uses,
# also relative to `app/assets/javascripts`
def get_graphql_query_as_string(query_path, fragment_paths = [])
[query_path, *fragment_paths].map do |path|
File.read(File.join(Rails.root, '/app/assets/javascripts', path))
end.join("\n")
def get_graphql_query_as_string(query_path)
path = Rails.root / 'app/assets/javascripts' / query_path
queries = Gitlab::Graphql::Queries.find(path)
if queries.length == 1
queries.first.text(mode: Gitlab.ee? ? :ee : :ce )
else
raise "Could not find query file at #{path}, please check your query_path" % path
end
end
 
private
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment