improve namespace/database validation for graphql (#4718)

This commit is contained in:
Raphael Darley 2024-09-09 18:59:55 +01:00 committed by GitHub
parent 9927fc654a
commit 2eff350c19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 9 deletions

View file

@ -13,6 +13,10 @@ pub enum GqlError {
SchemaError(String),
#[error("Error resolving request: {0}")]
ResolverError(String),
#[error("No Namespace specified")]
UnpecifiedNamespace,
#[error("No Database specified")]
UnpecifiedDatabase,
#[error("Internal Error: {0}")]
InternalError(String),
#[error("Error converting value: {val} to type: {target}")]

View file

@ -78,8 +78,8 @@ pub async fn generate_schema(
) -> Result<Schema, GqlError> {
let kvs = datastore.as_ref();
let tx = kvs.transaction(TransactionType::Read, LockType::Optimistic).await?;
let ns = session.ns.as_ref().expect("missing ns should have been caught");
let db = session.db.as_ref().expect("missing db should have been caught");
let ns = session.ns.as_ref().ok_or(GqlError::UnpecifiedNamespace)?;
let db = session.db.as_ref().ok_or(GqlError::UnpecifiedDatabase)?;
let tbs = tx.all_tb(ns, db).await?;
let mut query = Object::new("Query");
let mut types: Vec<Type> = Vec::new();

View file

@ -4,17 +4,12 @@ mod common;
mod graphql_integration {
use std::time::Duration;
use assert_fs::assert;
use http::header::HeaderValue;
use http::{header, Method};
use reqwest::Client;
use http::header;
use serde_json::json;
use surrealdb::headers::{AUTH_DB, AUTH_NS};
use surrealdb::sql;
use test_log::test;
use ulid::Ulid;
use super::common::{self, StartServerArguments, PASS, USER};
use super::common;
#[test(tokio::test)]
async fn basic() -> Result<(), Box<dyn std::error::Error>> {