use std::marker::PhantomData;
use crate::queries::InputLiteral;
#[derive(Debug, Clone, Copy)]
pub enum VariableType {
List(&'static VariableType),
Nullable(&'static VariableType),
Named(&'static str),
}
pub trait QueryVariables {
type Fields: QueryVariablesFields;
const VARIABLES: &'static [(&'static str, VariableType)];
}
pub trait QueryVariablesFields {}
impl QueryVariables for () {
type Fields = ();
const VARIABLES: &'static [(&'static str, VariableType)] = &[];
}
impl QueryVariablesFields for () {}
pub trait QueryVariableLiterals {
fn get(&self, variable_name: &str) -> Option<InputLiteral>;
}
#[doc(hidden)]
pub struct VariableDefinition<Variables, Type> {
pub name: &'static str,
phantom: PhantomData<fn() -> (Variables, Type)>,
}
impl<Variables, Type> VariableDefinition<Variables, Type> {
pub fn new(name: &'static str) -> Self {
VariableDefinition {
name,
phantom: PhantomData,
}
}
}
#[cfg(test)]
mod tests {
use cynic::QueryVariableLiterals;
#[test]
fn query_variable_literals_is_object_safe() {
#[derive(QueryVariableLiterals)]
struct Blah {
x: String,
}
let _: Box<dyn QueryVariableLiterals> = Box::new(Blah { x: "hello".into() });
}
}