Skip to content

Commit 675fb3c

Browse files
authored
Merge pull request #696 from code0-tech/copilot/add-metadata-to-graphql
Add metadata query to GraphQL API
2 parents 8363975 + dea38b0 commit 675fb3c

File tree

10 files changed

+89
-0
lines changed

10 files changed

+89
-0
lines changed

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.0

app/graphql/types/metadata_type.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class MetadataType < Types::BaseObject
5+
description 'Application metadata'
6+
7+
field :extensions, [GraphQL::Types::String], null: false, description: 'List of loaded extensions'
8+
field :version, GraphQL::Types::String, null: false, description: 'Application version'
9+
end
10+
end

app/graphql/types/query_type.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class QueryType < Types::BaseObject
2222
field :application_settings, Types::ApplicationSettingsType, null: true,
2323
description: 'Get global application settings'
2424

25+
field :metadata, Types::MetadataType, null: false, description: 'Get application metadata'
26+
2527
field :echo, GraphQL::Types::String, null: false, description: 'Field available for use to test API access' do
2628
argument :message, GraphQL::Types::String, required: true, description: 'String to echo as response'
2729
end
@@ -65,6 +67,13 @@ def application_settings
6567
ApplicationSetting.current
6668
end
6769

70+
def metadata
71+
{
72+
version: Sagittarius::Version,
73+
extensions: Sagittarius::Extensions.active.map(&:to_s),
74+
}
75+
end
76+
6877
def echo(message:)
6978
message
7079
end

config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require_relative '../lib/sagittarius/utils'
1212
require_relative '../lib/sagittarius/extensions'
1313
require_relative '../lib/sagittarius/configuration'
14+
require_relative '../lib/sagittarius/version'
1415

1516
module Sagittarius
1617
class Application < Rails::Application

docs/graphql/object/metadata.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Metadata
3+
---
4+
5+
Application metadata
6+
7+
## Fields without arguments
8+
9+
| Name | Type | Description |
10+
|------|------|-------------|
11+
| `extensions` | [`[String!]!`](../scalar/string.md) | List of loaded extensions |
12+
| `version` | [`String!`](../scalar/string.md) | Application version |
13+

docs/graphql/object/query.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Root Query type
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 |
1516
| `organizations` | [`OrganizationConnection!`](../object/organizationconnection.md) | Find organizations |
1617
| `userAbilities` | [`InstanceUserAbilities!`](../object/instanceuserabilities.md) | Abilities for the current user on this Instance |
1718
| `users` | [`UserConnection!`](../object/userconnection.md) | Find users |

lib/sagittarius/version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
module Sagittarius
4+
Version = File.read(File.expand_path('../../VERSION', __dir__)).strip.freeze
5+
end
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 Types::MetadataType do
6+
let(:fields) do
7+
%w[
8+
version
9+
extensions
10+
]
11+
end
12+
13+
it { expect(described_class.graphql_name).to eq('Metadata') }
14+
it { expect(described_class).to have_graphql_fields(fields) }
15+
end

spec/graphql/types/query_type_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
currentAuthentication
1010
currentUser
1111
echo
12+
metadata
1213
organization
1314
organizations
1415
users
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe 'metadata Query' do
6+
include GraphqlHelpers
7+
8+
let(:query) do
9+
<<~QUERY
10+
query {
11+
metadata {
12+
version
13+
extensions
14+
}
15+
}
16+
QUERY
17+
end
18+
19+
before { post_graphql query }
20+
21+
it 'returns the application version' do
22+
expect(graphql_data_at(:metadata, :version)).to eq(Sagittarius::Version)
23+
end
24+
25+
it 'returns the list of active extensions' do
26+
expected_extensions = Sagittarius::Extensions.active.map(&:to_s)
27+
expect(graphql_data_at(:metadata, :extensions)).to match_array(expected_extensions)
28+
end
29+
30+
it 'does not require authentication' do
31+
expect(graphql_errors).to be_nil
32+
end
33+
end

0 commit comments

Comments
 (0)