feat: make introspection
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
commit
6622e327a1
2
.drone.yml
Normal file
2
.drone.yml
Normal file
@ -0,0 +1,2 @@
|
||||
kind: template
|
||||
load: cuddle-rust-cli-plan.yaml
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
target/
|
||||
.cuddle/
|
2182
Cargo.lock
generated
Normal file
2182
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[workspace]
|
||||
members = ["crates/*"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
|
||||
anyhow = { version = "1" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
tracing-subscriber = { version = "0.3.18" }
|
||||
clap = { version = "4", features = ["derive", "env"] }
|
||||
dotenv = { version = "0.15" }
|
1
crates/graphql-schema/.gitignore
vendored
Normal file
1
crates/graphql-schema/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
20
crates/graphql-schema/Cargo.toml
Normal file
20
crates/graphql-schema/Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "graphql-schema"
|
||||
edition = "2021"
|
||||
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
clap.workspace = true
|
||||
dotenv.workspace = true
|
||||
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
uuid = { version = "1.7.0", features = ["v4"] }
|
||||
graphql_client = { version = "0.14.0" }
|
||||
reqwest = { version = "0.12.10", features = ["json"] }
|
||||
cynic-introspection = "3.9.1"
|
||||
cynic = { version = "3.9.1", features = ["http-reqwest", "reqwest", "serde_json"] }
|
90
crates/graphql-schema/src/main.rs
Normal file
90
crates/graphql-schema/src/main.rs
Normal file
@ -0,0 +1,90 @@
|
||||
use std::{io::Write, path::PathBuf};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
||||
struct Command {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Download {
|
||||
#[arg(long, env = "ENDPOINT")]
|
||||
endpoint: String,
|
||||
|
||||
#[arg(long, env = "AUTHORIZATION")]
|
||||
authorization: Option<String>,
|
||||
|
||||
#[arg(long = "output-file", env = "OUTPUT_FILE")]
|
||||
output_file: Option<PathBuf>,
|
||||
|
||||
#[arg(long = "output-stdout", env = "OUTPUT_STDOUT", default_value = "false")]
|
||||
output_stdout: bool,
|
||||
},
|
||||
}
|
||||
|
||||
use cynic::{http::ReqwestExt, QueryBuilder};
|
||||
use cynic_introspection::IntrospectionQuery;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_writer(std::io::stderr)
|
||||
.finish()
|
||||
.init();
|
||||
|
||||
let cli = Command::parse();
|
||||
tracing::debug!("Starting cli");
|
||||
|
||||
if let Some(Commands::Download {
|
||||
endpoint,
|
||||
authorization,
|
||||
output_file,
|
||||
output_stdout,
|
||||
}) = cli.command
|
||||
{
|
||||
tracing::info!("making request to: {}", endpoint);
|
||||
let client = reqwest::Client::new();
|
||||
let mut res = client.post(endpoint);
|
||||
if let Some(token) = authorization {
|
||||
res = res.bearer_auth(token);
|
||||
}
|
||||
|
||||
let schema = res
|
||||
.run_graphql(IntrospectionQuery::build(()))
|
||||
.await?
|
||||
.data
|
||||
.ok_or(anyhow::anyhow!("failed to get data"))?
|
||||
.into_schema()?;
|
||||
|
||||
let mut output = String::new();
|
||||
schema.write_sdl(&mut output)?;
|
||||
tracing::info!("formatted graphql file");
|
||||
|
||||
if let Some(output_file) = output_file {
|
||||
tracing::info!("outputting to file: {}", output_file.display());
|
||||
|
||||
let mut file = tokio::fs::File::create(output_file).await?;
|
||||
file.write_all(output.as_bytes()).await?;
|
||||
file.flush().await?;
|
||||
}
|
||||
|
||||
if output_stdout {
|
||||
tracing::info!("outputting to stdout");
|
||||
|
||||
let mut stdout = tokio::io::stdout();
|
||||
stdout.write_all(output.as_bytes()).await?;
|
||||
stdout.flush().await?;
|
||||
}
|
||||
}
|
||||
|
||||
std::io::stderr().flush()?;
|
||||
|
||||
Ok(())
|
||||
}
|
17
cuddle.yaml
Normal file
17
cuddle.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json
|
||||
|
||||
base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-cli-plan.git"
|
||||
|
||||
vars:
|
||||
service: "graphql-schema"
|
||||
registry: kasperhermansen
|
||||
|
||||
please:
|
||||
project:
|
||||
owner: kjuulh
|
||||
repository: "graphql-schema"
|
||||
branch: "main"
|
||||
settings:
|
||||
api_url: "https://git.front.kjuulh.io"
|
||||
actions:
|
||||
rust:
|
3
renovate.json
Normal file
3
renovate.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
15
templates/docker-compose.yaml
Normal file
15
templates/docker-compose.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
version: "3"
|
||||
services:
|
||||
crdb:
|
||||
restart: 'always'
|
||||
image: 'cockroachdb/cockroach:v23.1.14'
|
||||
command: 'start-single-node --advertise-addr 0.0.0.0 --insecure'
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"]
|
||||
interval: '10s'
|
||||
timeout: '30s'
|
||||
retries: 5
|
||||
start_period: '20s'
|
||||
ports:
|
||||
- 8080:8080
|
||||
- '26257:26257'
|
Loading…
Reference in New Issue
Block a user