improve namespace/database validation for graphql (#4718)
This commit is contained in:
parent
9927fc654a
commit
2eff350c19
3 changed files with 8 additions and 9 deletions
|
@ -13,6 +13,10 @@ pub enum GqlError {
|
||||||
SchemaError(String),
|
SchemaError(String),
|
||||||
#[error("Error resolving request: {0}")]
|
#[error("Error resolving request: {0}")]
|
||||||
ResolverError(String),
|
ResolverError(String),
|
||||||
|
#[error("No Namespace specified")]
|
||||||
|
UnpecifiedNamespace,
|
||||||
|
#[error("No Database specified")]
|
||||||
|
UnpecifiedDatabase,
|
||||||
#[error("Internal Error: {0}")]
|
#[error("Internal Error: {0}")]
|
||||||
InternalError(String),
|
InternalError(String),
|
||||||
#[error("Error converting value: {val} to type: {target}")]
|
#[error("Error converting value: {val} to type: {target}")]
|
||||||
|
|
|
@ -78,8 +78,8 @@ pub async fn generate_schema(
|
||||||
) -> Result<Schema, GqlError> {
|
) -> Result<Schema, GqlError> {
|
||||||
let kvs = datastore.as_ref();
|
let kvs = datastore.as_ref();
|
||||||
let tx = kvs.transaction(TransactionType::Read, LockType::Optimistic).await?;
|
let tx = kvs.transaction(TransactionType::Read, LockType::Optimistic).await?;
|
||||||
let ns = session.ns.as_ref().expect("missing ns should have been caught");
|
let ns = session.ns.as_ref().ok_or(GqlError::UnpecifiedNamespace)?;
|
||||||
let db = session.db.as_ref().expect("missing db should have been caught");
|
let db = session.db.as_ref().ok_or(GqlError::UnpecifiedDatabase)?;
|
||||||
let tbs = tx.all_tb(ns, db).await?;
|
let tbs = tx.all_tb(ns, db).await?;
|
||||||
let mut query = Object::new("Query");
|
let mut query = Object::new("Query");
|
||||||
let mut types: Vec<Type> = Vec::new();
|
let mut types: Vec<Type> = Vec::new();
|
||||||
|
|
|
@ -4,17 +4,12 @@ mod common;
|
||||||
mod graphql_integration {
|
mod graphql_integration {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use assert_fs::assert;
|
use http::header;
|
||||||
use http::header::HeaderValue;
|
|
||||||
use http::{header, Method};
|
|
||||||
use reqwest::Client;
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use surrealdb::headers::{AUTH_DB, AUTH_NS};
|
|
||||||
use surrealdb::sql;
|
|
||||||
use test_log::test;
|
use test_log::test;
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
|
|
||||||
use super::common::{self, StartServerArguments, PASS, USER};
|
use super::common;
|
||||||
|
|
||||||
#[test(tokio::test)]
|
#[test(tokio::test)]
|
||||||
async fn basic() -> Result<(), Box<dyn std::error::Error>> {
|
async fn basic() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
Loading…
Reference in a new issue