Skip to content

Commit 4918580

Browse files
authored
Merge pull request #726 from code0-tech/721-application-settings-and-metadata-should-be-nested-in-one-field-idk-why
Create an application type for metadata and version
2 parents 61155dc + 8bf0714 commit 4918580

File tree

9 files changed

+124
-50
lines changed

9 files changed

+124
-50
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class ApplicationType < Types::BaseObject
5+
description 'Represents the application instance'
6+
7+
field :metadata, Types::MetadataType, null: false,
8+
description: 'Metadata about the application'
9+
10+
field :settings, Types::ApplicationSettingsType, null: true,
11+
description: 'Global application settings'
12+
13+
def metadata
14+
{}
15+
end
16+
17+
def settings
18+
ApplicationSetting.current
19+
end
20+
end
21+
end

app/graphql/types/metadata_type.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@ class MetadataType < Types::BaseObject
66

77
field :extensions, [GraphQL::Types::String], null: false, description: 'List of loaded extensions'
88
field :version, GraphQL::Types::String, null: false, description: 'Application version'
9+
10+
def extensions
11+
Sagittarius::Extensions.active
12+
end
13+
14+
def version
15+
Sagittarius::Version
16+
end
917
end
1018
end

app/graphql/types/query_type.rb

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ class QueryType < Types::BaseObject
1919
field :current_user, Types::UserType, null: true, description: 'Get the currently logged in user'
2020
# rubocop:enable GraphQL/ExtractType
2121

22-
field :application_settings, Types::ApplicationSettingsType, null: true,
23-
description: 'Get global application settings'
24-
25-
field :metadata, Types::MetadataType, null: false, description: 'Get application metadata'
22+
field :application, Types::ApplicationType, null: false,
23+
description: 'Get application information'
2624

2725
field :echo, GraphQL::Types::String, null: false, description: 'Field available for use to test API access' do
2826
argument :message, GraphQL::Types::String, required: true, description: 'String to echo as response'
@@ -67,15 +65,8 @@ def nodes(ids:)
6765
ids.map { |id| context.schema.object_from_id(id, context) }
6866
end
6967

70-
def application_settings
71-
ApplicationSetting.current
72-
end
73-
74-
def metadata
75-
{
76-
version: Sagittarius::Version,
77-
extensions: Sagittarius::Extensions.active.map(&:to_s),
78-
}
68+
def application
69+
{}
7970
end
8071

8172
def echo(message:)

docs/graphql/object/application.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Application
3+
---
4+
5+
Represents the application instance
6+
7+
## Fields without arguments
8+
9+
| Name | Type | Description |
10+
|------|------|-------------|
11+
| `metadata` | [`Metadata!`](../object/metadata.md) | Metadata about the application |
12+
| `settings` | [`ApplicationSettings`](../object/applicationsettings.md) | Global application settings |
13+

docs/graphql/object/query.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ Root Query type
88

99
| Name | Type | Description |
1010
|------|------|-------------|
11-
| `applicationSettings` | [`ApplicationSettings`](../object/applicationsettings.md) | Get global application settings |
11+
| `application` | [`Application!`](../object/application.md) | Get application information |
1212
| `currentAuthentication` | [`Authentication`](../union/authentication.md) | Get the currently logged in authentication |
1313
| `currentUser` | [`User`](../object/user.md) | Get the currently logged in user |
1414
| `globalRuntimes` | [`RuntimeConnection!`](../object/runtimeconnection.md) | Find runtimes |
15-
| `metadata` | [`Metadata!`](../object/metadata.md) | Get application metadata |
1615
| `organizations` | [`OrganizationConnection!`](../object/organizationconnection.md) | Find organizations |
1716
| `userAbilities` | [`InstanceUserAbilities!`](../object/instanceuserabilities.md) | Abilities for the current user on this Instance |
1817
| `users` | [`UserConnection!`](../object/userconnection.md) | Find users |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe SagittariusSchema.types['Application'] do
6+
let(:fields) do
7+
%w[
8+
settings
9+
metadata
10+
]
11+
end
12+
13+
it { expect(described_class.graphql_name).to eq('Application') }
14+
it { expect(described_class).to have_graphql_fields(fields) }
15+
end

spec/graphql/types/query_type_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
RSpec.describe SagittariusSchema.types['Query'] do
66
let(:fields) do
77
%w[
8-
applicationSettings
8+
application
99
currentAuthentication
1010
currentUser
1111
echo
12-
metadata
1312
organization
1413
organizations
1514
users
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe 'application Query' do
6+
include GraphqlHelpers
7+
8+
let(:query) do
9+
<<~QUERY
10+
query {
11+
application {
12+
settings {
13+
userRegistrationEnabled
14+
organizationCreationRestricted
15+
}
16+
metadata {
17+
version
18+
extensions
19+
}
20+
}
21+
}
22+
QUERY
23+
end
24+
25+
let(:current_user) { nil }
26+
27+
before do
28+
post_graphql(query, current_user: current_user)
29+
end
30+
31+
context 'when querying application settings' do
32+
let(:current_user) { create(:user, :admin) }
33+
34+
it 'returns the application settings' do
35+
settings = graphql_data_at(:application, :settings)
36+
37+
expect(settings['userRegistrationEnabled'])
38+
.to eq(ApplicationSetting.current['user_registration_enabled'])
39+
expect(settings['organizationCreationRestricted'])
40+
.to eq(ApplicationSetting.current['organization_creation_restricted'])
41+
end
42+
end
43+
44+
it 'returns null application settings because of permissions' do
45+
settings = graphql_data_at(:application, :settings)
46+
expect(settings).to be_nil
47+
end
48+
49+
it 'returns the application version' do
50+
expect(graphql_data_at(:application, :metadata, :version)).to eq(Sagittarius::Version)
51+
end
52+
53+
it 'returns the list of active extensions' do
54+
expected_extensions = Sagittarius::Extensions.active.map(&:to_s)
55+
expect(graphql_data_at(:application, :metadata, :extensions)).to match_array(expected_extensions)
56+
end
57+
58+
it 'does not require authentication' do
59+
expect(graphql_errors).to be_nil
60+
end
61+
end

spec/requests/graphql/query/metadata_query_spec.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)