Skip to content

Commit

Permalink
[GraphQL] Add available versions query to service config (MystenLabs#…
Browse files Browse the repository at this point in the history
…17503)

## Description 

Adds available versions query to the service config. Uses the crate's
version if no `versions` section exists in the `config.toml` file.

## Test plan 

Existing tests. Manual query on local instance. 

## No versions in config.toml file
```graphql
{
  serviceConfig {
    availableVersions
  }
}
```

```json
{
  "data": {
    "serviceConfig": {
      "availableVersions": [
        "2024.7"
      ]
    }
  }
}
```

## Start server with config toml file
```toml
[limits]
max-query-depth = 15
max-query-nodes = 500
max-output-nodes = 100000
max-query-payload-size = 5000
max-db-query-cost = 20000
default-page-size = 5
max-page-size = 10
request-timeout-ms = 15000
max-type-argument-depth = 16
max-type-argument-width = 32
max-type-nodes = 256
max-move-value-depth = 128

[versions]
versions = ["2024.1", "2024.4", "2024.7"]
```
Same query
```json
{
  "data": {
    "serviceConfig": {
      "availableVersions": [
        "2024.1",
        "2024.4",
        "2024.7"
      ]
    }
  }
}
```
 
---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
stefan-mysten authored May 10, 2024
1 parent 1f48cfe commit 76da558
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
13 changes: 12 additions & 1 deletion crates/sui-graphql-e2e-tests/tests/call/simple.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
processed 25 tasks
processed 26 tasks

init:
validator_0: object(0,0)
Expand Down Expand Up @@ -290,3 +290,14 @@ task 24 'run'. lines 181-181:
created: object(24,0)
mutated: object(0,1)
gas summary: computation_cost: 235000, storage_cost: 2302800, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 25 'run-graphql'. lines 183-188:
Response: {
"data": {
"serviceConfig": {
"availableVersions": [
"2024.7"
]
}
}
}
7 changes: 7 additions & 0 deletions crates/sui-graphql-e2e-tests/tests/call/simple.move
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,10 @@ module Test::M1 {
//# run Test::M1::create --args 0 @A --gas-price 1000

//# run Test::M1::create --args 0 @A --gas-price 235

//# run-graphql
{
serviceConfig {
availableVersions
}
}
4 changes: 4 additions & 0 deletions crates/sui-graphql-rpc/schema/current_progress_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,10 @@ type ServiceConfig {
"""
isEnabled(feature: Feature!): Boolean!
"""
List the available versions for this GraphQL service.
"""
availableVersions: [String!]!
"""
List of all features that are enabled on this GraphQL service.
"""
enabledFeatures: [Feature!]!
Expand Down
1 change: 1 addition & 0 deletions crates/sui-graphql-rpc/schema/draft_target_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ type AvailableRange {
}

type ServiceConfig {
availableVersions: [String!]
enabledFeatures: [Feature!]
isEnabled(feature: Feature!): Boolean!

Expand Down
28 changes: 27 additions & 1 deletion crates/sui-graphql-rpc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use fastcrypto_zkp::bn254::zk_login_api::ZkLoginEnv;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeSet, fmt::Display, time::Duration};
use sui_json_rpc::name_service::NameServiceConfig;

// TODO: calculate proper cost limits

/// These values are set to support TS SDK shim layer queries for json-rpc compatibility.
Expand Down Expand Up @@ -80,6 +79,9 @@ pub struct ConnectionConfig {
#[derive(Serialize, Clone, Deserialize, Debug, Eq, PartialEq, Default)]
#[serde(rename_all = "kebab-case")]
pub struct ServiceConfig {
#[serde(default)]
pub(crate) versions: Versions,

#[serde(default)]
pub(crate) limits: Limits,

Expand All @@ -99,6 +101,13 @@ pub struct ServiceConfig {
pub(crate) zklogin: ZkLoginConfig,
}

#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct Versions {
#[serde(default)]
versions: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Copy)]
#[serde(rename_all = "kebab-case")]
pub struct Limits {
Expand Down Expand Up @@ -237,6 +246,11 @@ impl ServiceConfig {
!self.disabled_features.contains(&feature)
}

/// List the available versions for this GraphQL service.
async fn available_versions(&self) -> Vec<String> {
self.versions.versions.clone()
}

/// List of all features that are enabled on this GraphQL service.
async fn enabled_features(&self) -> Vec<FunctionalGroup> {
FunctionalGroup::all()
Expand Down Expand Up @@ -426,6 +440,18 @@ impl BackgroundTasksConfig {
}
}

impl Default for Versions {
fn default() -> Self {
Self {
versions: vec![format!(
"{}.{}",
env!("CARGO_PKG_VERSION_MAJOR"),
env!("CARGO_PKG_VERSION_MINOR")
)],
}
}
}

impl Default for Ide {
fn default() -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3025,6 +3025,10 @@ type ServiceConfig {
"""
isEnabled(feature: Feature!): Boolean!
"""
List the available versions for this GraphQL service.
"""
availableVersions: [String!]!
"""
List of all features that are enabled on this GraphQL service.
"""
enabledFeatures: [Feature!]!
Expand Down

0 comments on commit 76da558

Please sign in to comment.