diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-05-23 09:55:14 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-06-06 10:58:54 +0200 |
commit | 9b65d4bb417fb4939289eab94487c894f0a62db6 (patch) | |
tree | 1f97b9a1bd0d722a3c3ff4e89ec13bdb7a3aec00 /spec/graphql | |
parent | c443133e779c4c508b9c6429dd4ba623d64f03f1 (diff) | |
download | gitlab-ce-9b65d4bb417fb4939289eab94487c894f0a62db6.tar.gz |
Initial setup GraphQL using graphql-ruby 1.8
- All definitions have been replaced by classes:
http://graphql-ruby.org/schema/class_based_api.html
- Authorization & Presentation have been refactored to work in the
class based system
- Loaders have been replaced by resolvers
- Times are now coersed as ISO 8601
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/gitlab_schema_spec.rb | 15 | ||||
-rw-r--r-- | spec/graphql/resolvers/merge_request_resolver_spec.rb (renamed from spec/graphql/loaders/iid_loader_spec.rb) | 6 | ||||
-rw-r--r-- | spec/graphql/resolvers/project_resolver_spec.rb (renamed from spec/graphql/loaders/full_path_loader_spec.rb) | 6 | ||||
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 5 | ||||
-rw-r--r-- | spec/graphql/types/query_type_spec.rb | 10 | ||||
-rw-r--r-- | spec/graphql/types/time_type_spec.rb | 14 |
6 files changed, 30 insertions, 26 deletions
diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb index f25cc2fd6c9..b892f6b44ed 100644 --- a/spec/graphql/gitlab_schema_spec.rb +++ b/spec/graphql/gitlab_schema_spec.rb @@ -6,26 +6,25 @@ describe GitlabSchema do end it 'enables the preload instrumenter' do - expect(field_instrumenters).to include(instance_of(::GraphQL::Preload::Instrument)) + expect(field_instrumenters).to include(BatchLoader::GraphQL) end it 'enables the authorization instrumenter' do - expect(field_instrumenters).to include(instance_of(::Gitlab::Graphql::Authorize)) + expect(field_instrumenters).to include(instance_of(::Gitlab::Graphql::Authorize::Instrumentation)) end it 'enables using presenters' do - expect(field_instrumenters).to include(instance_of(::Gitlab::Graphql::Present)) + expect(field_instrumenters).to include(instance_of(::Gitlab::Graphql::Present::Instrumentation)) end it 'has the base mutation' do - pending <<~REASON - Having empty mutations breaks the automatic documentation in Graphiql, so removed for now." - REASON - expect(described_class.mutation).to eq(::Types::MutationType) + pending('Adding an empty mutation breaks the documentation explorer') + + expect(described_class.mutation).to eq(::Types::MutationType.to_graphql) end it 'has the base query' do - expect(described_class.query).to eq(::Types::QueryType) + expect(described_class.query).to eq(::Types::QueryType.to_graphql) end def field_instrumenters diff --git a/spec/graphql/loaders/iid_loader_spec.rb b/spec/graphql/resolvers/merge_request_resolver_spec.rb index 0a57d7c4ed4..af015533209 100644 --- a/spec/graphql/loaders/iid_loader_spec.rb +++ b/spec/graphql/resolvers/merge_request_resolver_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Loaders::IidLoader do +describe Resolvers::MergeRequestResolver do include GraphqlHelpers set(:project) { create(:project, :repository) } @@ -17,7 +17,7 @@ describe Loaders::IidLoader do let(:other_full_path) { other_project.full_path } let(:other_iid) { other_merge_request.iid } - describe '.merge_request' do + describe '#resolve' do it 'batch-resolves merge requests by target project full path and IID' do path = full_path # avoid database query @@ -53,6 +53,6 @@ describe Loaders::IidLoader do end def resolve_mr(full_path, iid) - resolve(described_class, :merge_request, args: { project: full_path, iid: iid }) + resolve(described_class, args: { full_path: full_path, iid: iid }) end end diff --git a/spec/graphql/loaders/full_path_loader_spec.rb b/spec/graphql/resolvers/project_resolver_spec.rb index 2732dd8c9da..d4990c6492c 100644 --- a/spec/graphql/loaders/full_path_loader_spec.rb +++ b/spec/graphql/resolvers/project_resolver_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Loaders::FullPathLoader do +describe Resolvers::ProjectResolver do include GraphqlHelpers set(:project1) { create(:project) } @@ -8,7 +8,7 @@ describe Loaders::FullPathLoader do set(:other_project) { create(:project) } - describe '.project' do + describe '#resolve' do it 'batch-resolves projects by full path' do paths = [project1.full_path, project2.full_path] @@ -27,6 +27,6 @@ describe Loaders::FullPathLoader do end def resolve_project(full_path) - resolve(described_class, :project, args: { full_path: full_path }) + resolve(described_class, args: { full_path: full_path }) end end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb new file mode 100644 index 00000000000..e0f89105b86 --- /dev/null +++ b/spec/graphql/types/project_type_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe GitlabSchema.types['Project'] do + it { expect(described_class.graphql_name).to eq('Project') } +end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 17d9395504c..8488252fd59 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe GitlabSchema.types['Query'] do it 'is called Query' do - expect(described_class.name).to eq('Query') + expect(described_class.graphql_name).to eq('Query') end it { is_expected.to have_graphql_fields(:project, :merge_request, :echo) } @@ -13,7 +13,7 @@ describe GitlabSchema.types['Query'] do it 'finds projects by full path' do is_expected.to have_graphql_arguments(:full_path) is_expected.to have_graphql_type(Types::ProjectType) - is_expected.to have_graphql_resolver(Loaders::FullPathLoader[:project]) + is_expected.to have_graphql_resolver(Resolvers::ProjectResolver) end it 'authorizes with read_project' do @@ -22,12 +22,12 @@ describe GitlabSchema.types['Query'] do end describe 'merge_request field' do - subject { described_class.fields['merge_request'] } + subject { described_class.fields['mergeRequest'] } it 'finds MRs by project and IID' do - is_expected.to have_graphql_arguments(:project, :iid) + is_expected.to have_graphql_arguments(:full_path, :iid) is_expected.to have_graphql_type(Types::MergeRequestType) - is_expected.to have_graphql_resolver(Loaders::IidLoader[:merge_request]) + is_expected.to have_graphql_resolver(Resolvers::MergeRequestResolver) end it 'authorizes with read_merge_request' do diff --git a/spec/graphql/types/time_type_spec.rb b/spec/graphql/types/time_type_spec.rb index 087655cc67d..4196d9d27d4 100644 --- a/spec/graphql/types/time_type_spec.rb +++ b/spec/graphql/types/time_type_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' describe GitlabSchema.types['Time'] do - let(:float) { 1504630455.96215 } - let(:time) { Time.at(float) } + let(:iso) { "2018-06-04T15:23:50+02:00" } + let(:time) { Time.parse(iso) } - it { expect(described_class.name).to eq('Time') } + it { expect(described_class.graphql_name).to eq('Time') } - it 'coerces Time into fractional seconds since epoch' do - expect(described_class.coerce_isolated_result(time)).to eq(float) + it 'coerces Time object into ISO 8601' do + expect(described_class.coerce_isolated_result(time)).to eq(iso) end - it 'coerces fractional seconds since epoch into Time' do - expect(described_class.coerce_isolated_input(float)).to eq(time) + it 'coerces an ISO-time into Time object' do + expect(described_class.coerce_isolated_input(iso)).to eq(time) end end |