2020-09-14 00:37:15 +00:00
|
|
|
mod cache_control;
|
2020-09-23 00:04:00 +00:00
|
|
|
mod export_sdl;
|
2020-09-14 00:37:15 +00:00
|
|
|
|
2020-09-06 06:16:36 +00:00
|
|
|
use crate::parser::types::{BaseType as ParsedBaseType, Type as ParsedType};
|
2020-03-21 01:32:13 +00:00
|
|
|
use crate::validators::InputValueValidator;
|
2020-09-23 00:04:00 +00:00
|
|
|
use crate::{model, Any, Type, Value};
|
2020-05-16 02:05:48 +00:00
|
|
|
use indexmap::map::IndexMap;
|
|
|
|
use indexmap::set::IndexSet;
|
2020-03-06 15:58:43 +00:00
|
|
|
use std::collections::{HashMap, HashSet};
|
2020-03-21 01:32:13 +00:00
|
|
|
use std::sync::Arc;
|
2020-03-04 06:24:44 +00:00
|
|
|
|
2020-09-14 00:37:15 +00:00
|
|
|
pub use cache_control::CacheControl;
|
|
|
|
|
2020-09-06 05:38:31 +00:00
|
|
|
fn strip_brackets(type_name: &str) -> Option<&str> {
|
|
|
|
if let Some(rest) = type_name.strip_prefix('[') {
|
|
|
|
Some(&rest[..rest.len() - 1])
|
2020-03-08 12:35:36 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 08:00:26 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
2020-05-15 02:08:37 +00:00
|
|
|
pub enum MetaTypeName<'a> {
|
2020-03-08 12:35:36 +00:00
|
|
|
List(&'a str),
|
|
|
|
NonNull(&'a str),
|
2020-03-10 06:14:09 +00:00
|
|
|
Named(&'a str),
|
2020-03-08 12:35:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
impl<'a> std::fmt::Display for MetaTypeName<'a> {
|
2020-04-05 08:00:26 +00:00
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaTypeName::Named(name) => write!(f, "{}", name),
|
|
|
|
MetaTypeName::NonNull(name) => write!(f, "{}!", name),
|
|
|
|
MetaTypeName::List(name) => write!(f, "[{}]", name),
|
2020-04-05 08:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
impl<'a> MetaTypeName<'a> {
|
|
|
|
pub fn create(type_name: &str) -> MetaTypeName {
|
2020-09-06 05:38:31 +00:00
|
|
|
if let Some(type_name) = type_name.strip_suffix('!') {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaTypeName::NonNull(type_name)
|
2020-09-06 05:38:31 +00:00
|
|
|
} else if let Some(type_name) = strip_brackets(type_name) {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaTypeName::List(type_name)
|
2020-03-08 12:35:36 +00:00
|
|
|
} else {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaTypeName::Named(type_name)
|
2020-03-08 12:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-09 10:05:52 +00:00
|
|
|
|
2020-04-06 10:30:38 +00:00
|
|
|
pub fn concrete_typename(type_name: &str) -> &str {
|
2020-05-15 02:08:37 +00:00
|
|
|
match MetaTypeName::create(type_name) {
|
|
|
|
MetaTypeName::List(type_name) => Self::concrete_typename(type_name),
|
|
|
|
MetaTypeName::NonNull(type_name) => Self::concrete_typename(type_name),
|
|
|
|
MetaTypeName::Named(type_name) => type_name,
|
2020-03-09 10:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-10 12:35:25 +00:00
|
|
|
|
|
|
|
pub fn is_non_null(&self) -> bool {
|
2020-09-06 05:38:31 +00:00
|
|
|
matches!(self, MetaTypeName::NonNull(_))
|
2020-03-10 12:35:25 +00:00
|
|
|
}
|
2020-04-05 08:00:26 +00:00
|
|
|
|
|
|
|
pub fn unwrap_non_null(&self) -> Self {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaTypeName::NonNull(ty) => MetaTypeName::create(ty),
|
2020-04-05 08:14:22 +00:00
|
|
|
_ => *self,
|
2020-04-05 08:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
pub fn is_subtype(&self, sub: &MetaTypeName<'_>) -> bool {
|
2020-04-05 08:00:26 +00:00
|
|
|
match (self, sub) {
|
2020-05-15 02:08:37 +00:00
|
|
|
(MetaTypeName::NonNull(super_type), MetaTypeName::NonNull(sub_type))
|
|
|
|
| (MetaTypeName::Named(super_type), MetaTypeName::NonNull(sub_type)) => {
|
|
|
|
MetaTypeName::create(super_type).is_subtype(&MetaTypeName::create(sub_type))
|
2020-04-05 08:00:26 +00:00
|
|
|
}
|
2020-05-15 02:08:37 +00:00
|
|
|
(MetaTypeName::Named(super_type), MetaTypeName::Named(sub_type)) => {
|
|
|
|
super_type == sub_type
|
|
|
|
}
|
|
|
|
(MetaTypeName::List(super_type), MetaTypeName::List(sub_type)) => {
|
|
|
|
MetaTypeName::create(super_type).is_subtype(&MetaTypeName::create(sub_type))
|
2020-04-05 08:00:26 +00:00
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2020-03-08 12:35:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 09:20:12 +00:00
|
|
|
#[derive(Clone)]
|
2020-05-15 02:08:37 +00:00
|
|
|
pub struct MetaInputValue {
|
2020-03-03 03:48:00 +00:00
|
|
|
pub name: &'static str,
|
|
|
|
pub description: Option<&'static str>,
|
|
|
|
pub ty: String,
|
2020-05-26 10:34:43 +00:00
|
|
|
pub default_value: Option<String>,
|
2020-03-22 01:34:32 +00:00
|
|
|
pub validator: Option<Arc<dyn InputValueValidator>>,
|
2020-03-03 03:48:00 +00:00
|
|
|
}
|
2020-03-02 11:25:21 +00:00
|
|
|
|
2020-03-19 09:20:12 +00:00
|
|
|
#[derive(Clone)]
|
2020-05-15 02:08:37 +00:00
|
|
|
pub struct MetaField {
|
2020-03-19 09:20:12 +00:00
|
|
|
pub name: String,
|
2020-03-03 03:48:00 +00:00
|
|
|
pub description: Option<&'static str>,
|
2020-05-16 02:05:48 +00:00
|
|
|
pub args: IndexMap<&'static str, MetaInputValue>,
|
2020-03-03 03:48:00 +00:00
|
|
|
pub ty: String,
|
|
|
|
pub deprecation: Option<&'static str>,
|
2020-03-22 08:45:59 +00:00
|
|
|
pub cache_control: CacheControl,
|
2020-04-09 14:03:09 +00:00
|
|
|
pub external: bool,
|
|
|
|
pub requires: Option<&'static str>,
|
|
|
|
pub provides: Option<&'static str>,
|
2020-03-03 03:48:00 +00:00
|
|
|
}
|
2020-03-02 00:24:49 +00:00
|
|
|
|
2020-03-19 09:20:12 +00:00
|
|
|
#[derive(Clone)]
|
2020-05-15 02:08:37 +00:00
|
|
|
pub struct MetaEnumValue {
|
2020-03-03 03:48:00 +00:00
|
|
|
pub name: &'static str,
|
|
|
|
pub description: Option<&'static str>,
|
|
|
|
pub deprecation: Option<&'static str>,
|
|
|
|
}
|
2020-03-02 00:24:49 +00:00
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
pub enum MetaType {
|
2020-03-03 11:15:18 +00:00
|
|
|
Scalar {
|
|
|
|
name: String,
|
|
|
|
description: Option<&'static str>,
|
2020-03-08 12:35:36 +00:00
|
|
|
is_valid: fn(value: &Value) -> bool,
|
2020-03-03 11:15:18 +00:00
|
|
|
},
|
2020-03-03 03:48:00 +00:00
|
|
|
Object {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: String,
|
2020-03-03 11:15:18 +00:00
|
|
|
description: Option<&'static str>,
|
2020-05-16 02:05:48 +00:00
|
|
|
fields: IndexMap<String, MetaField>,
|
2020-03-22 08:45:59 +00:00
|
|
|
cache_control: CacheControl,
|
2020-04-09 14:03:09 +00:00
|
|
|
extends: bool,
|
|
|
|
keys: Option<Vec<String>>,
|
2020-03-03 03:48:00 +00:00
|
|
|
},
|
|
|
|
Interface {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: String,
|
2020-03-03 11:15:18 +00:00
|
|
|
description: Option<&'static str>,
|
2020-05-16 02:05:48 +00:00
|
|
|
fields: IndexMap<String, MetaField>,
|
|
|
|
possible_types: IndexSet<String>,
|
2020-04-09 14:03:09 +00:00
|
|
|
extends: bool,
|
|
|
|
keys: Option<Vec<String>>,
|
2020-03-03 03:48:00 +00:00
|
|
|
},
|
|
|
|
Union {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: String,
|
2020-03-03 11:15:18 +00:00
|
|
|
description: Option<&'static str>,
|
2020-05-16 02:05:48 +00:00
|
|
|
possible_types: IndexSet<String>,
|
2020-03-03 03:48:00 +00:00
|
|
|
},
|
|
|
|
Enum {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: String,
|
2020-03-03 11:15:18 +00:00
|
|
|
description: Option<&'static str>,
|
2020-05-16 02:05:48 +00:00
|
|
|
enum_values: IndexMap<&'static str, MetaEnumValue>,
|
2020-03-03 03:48:00 +00:00
|
|
|
},
|
|
|
|
InputObject {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: String,
|
2020-03-03 11:15:18 +00:00
|
|
|
description: Option<&'static str>,
|
2020-05-16 02:05:48 +00:00
|
|
|
input_fields: IndexMap<String, MetaInputValue>,
|
2020-03-03 03:48:00 +00:00
|
|
|
},
|
2020-03-04 06:24:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
impl MetaType {
|
|
|
|
pub fn field_by_name(&self, name: &str) -> Option<&MetaField> {
|
2020-03-08 12:35:36 +00:00
|
|
|
self.fields().and_then(|fields| fields.get(name))
|
|
|
|
}
|
|
|
|
|
2020-05-16 02:05:48 +00:00
|
|
|
pub fn fields(&self) -> Option<&IndexMap<String, MetaField>> {
|
2020-03-08 12:35:36 +00:00
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Object { fields, .. } => Some(&fields),
|
|
|
|
MetaType::Interface { fields, .. } => Some(&fields),
|
2020-03-08 12:35:36 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn name(&self) -> &str {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Scalar { name, .. } => &name,
|
|
|
|
MetaType::Object { name, .. } => name,
|
|
|
|
MetaType::Interface { name, .. } => name,
|
|
|
|
MetaType::Union { name, .. } => name,
|
|
|
|
MetaType::Enum { name, .. } => name,
|
|
|
|
MetaType::InputObject { name, .. } => name,
|
2020-03-08 12:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-09 04:08:50 +00:00
|
|
|
|
|
|
|
pub fn is_composite(&self) -> bool {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Object { .. } => true,
|
|
|
|
MetaType::Interface { .. } => true,
|
|
|
|
MetaType::Union { .. } => true,
|
2020-03-09 04:08:50 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 08:00:26 +00:00
|
|
|
pub fn is_abstract(&self) -> bool {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Interface { .. } => true,
|
|
|
|
MetaType::Union { .. } => true,
|
2020-04-05 08:00:26 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 04:08:50 +00:00
|
|
|
pub fn is_leaf(&self) -> bool {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Enum { .. } => true,
|
|
|
|
MetaType::Scalar { .. } => true,
|
2020-03-09 04:08:50 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2020-03-10 06:14:09 +00:00
|
|
|
|
|
|
|
pub fn is_input(&self) -> bool {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Enum { .. } => true,
|
|
|
|
MetaType::Scalar { .. } => true,
|
|
|
|
MetaType::InputObject { .. } => true,
|
2020-03-10 06:14:09 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2020-03-10 10:07:47 +00:00
|
|
|
|
|
|
|
pub fn is_possible_type(&self, type_name: &str) -> bool {
|
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Interface { possible_types, .. } => possible_types.contains(type_name),
|
|
|
|
MetaType::Union { possible_types, .. } => possible_types.contains(type_name),
|
|
|
|
MetaType::Object { name, .. } => name == type_name,
|
2020-03-10 10:07:47 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2020-04-05 08:00:26 +00:00
|
|
|
|
2020-05-16 02:05:48 +00:00
|
|
|
pub fn possible_types(&self) -> Option<&IndexSet<String>> {
|
2020-04-05 08:00:26 +00:00
|
|
|
match self {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Interface { possible_types, .. } => Some(possible_types),
|
|
|
|
MetaType::Union { possible_types, .. } => Some(possible_types),
|
2020-04-05 08:00:26 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
pub fn type_overlap(&self, ty: &MetaType) -> bool {
|
|
|
|
if self as *const MetaType == ty as *const MetaType {
|
2020-04-05 08:00:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
match (self.is_abstract(), ty.is_abstract()) {
|
|
|
|
(true, true) => self
|
|
|
|
.possible_types()
|
|
|
|
.iter()
|
|
|
|
.copied()
|
|
|
|
.flatten()
|
|
|
|
.any(|type_name| ty.is_possible_type(type_name)),
|
|
|
|
(true, false) => self.is_possible_type(ty.name()),
|
|
|
|
(false, true) => ty.is_possible_type(self.name()),
|
|
|
|
(false, false) => false,
|
|
|
|
}
|
|
|
|
}
|
2020-03-08 12:35:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
pub struct MetaDirective {
|
2020-03-04 06:24:44 +00:00
|
|
|
pub name: &'static str,
|
|
|
|
pub description: Option<&'static str>,
|
|
|
|
pub locations: Vec<model::__DirectiveLocation>,
|
2020-05-16 02:05:48 +00:00
|
|
|
pub args: IndexMap<&'static str, MetaInputValue>,
|
2020-03-04 06:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Registry {
|
2020-09-23 00:04:00 +00:00
|
|
|
pub types: IndexMap<String, MetaType>,
|
2020-05-15 02:08:37 +00:00
|
|
|
pub directives: HashMap<String, MetaDirective>,
|
2020-03-06 15:58:43 +00:00
|
|
|
pub implements: HashMap<String, HashSet<String>>,
|
2020-03-08 12:35:36 +00:00
|
|
|
pub query_type: String,
|
|
|
|
pub mutation_type: Option<String>,
|
2020-03-17 09:26:59 +00:00
|
|
|
pub subscription_type: Option<String>,
|
2020-03-04 06:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Registry {
|
2020-05-15 02:08:37 +00:00
|
|
|
pub fn create_type<T: crate::Type, F: FnMut(&mut Registry) -> MetaType>(
|
2020-03-19 09:20:12 +00:00
|
|
|
&mut self,
|
|
|
|
mut f: F,
|
|
|
|
) -> String {
|
2020-03-04 06:24:44 +00:00
|
|
|
let name = T::type_name();
|
|
|
|
if !self.types.contains_key(name.as_ref()) {
|
2020-09-06 05:38:31 +00:00
|
|
|
// Inserting a fake type before calling the function allows recursive types to exist.
|
2020-03-05 13:34:31 +00:00
|
|
|
self.types.insert(
|
2020-09-06 05:38:31 +00:00
|
|
|
name.clone().into_owned(),
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Object {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: "".to_string(),
|
2020-03-05 13:34:31 +00:00
|
|
|
description: None,
|
2020-03-08 12:35:36 +00:00
|
|
|
fields: Default::default(),
|
2020-03-22 08:45:59 +00:00
|
|
|
cache_control: Default::default(),
|
2020-04-09 14:03:09 +00:00
|
|
|
extends: false,
|
|
|
|
keys: None,
|
2020-03-05 13:34:31 +00:00
|
|
|
},
|
|
|
|
);
|
2020-04-02 12:37:01 +00:00
|
|
|
let ty = f(self);
|
2020-09-06 05:38:31 +00:00
|
|
|
*self.types.get_mut(&*name).unwrap() = ty;
|
2020-03-04 06:24:44 +00:00
|
|
|
}
|
|
|
|
T::qualified_type_name()
|
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
pub fn add_directive(&mut self, directive: MetaDirective) {
|
2020-03-08 12:35:36 +00:00
|
|
|
self.directives
|
|
|
|
.insert(directive.name.to_string(), directive);
|
2020-03-04 06:24:44 +00:00
|
|
|
}
|
2020-03-06 15:58:43 +00:00
|
|
|
|
|
|
|
pub fn add_implements(&mut self, ty: &str, interface: &str) {
|
|
|
|
self.implements
|
|
|
|
.entry(ty.to_string())
|
|
|
|
.and_modify(|interfaces| {
|
|
|
|
interfaces.insert(interface.to_string());
|
|
|
|
})
|
|
|
|
.or_insert({
|
|
|
|
let mut interfaces = HashSet::new();
|
|
|
|
interfaces.insert(interface.to_string());
|
|
|
|
interfaces
|
|
|
|
});
|
|
|
|
}
|
2020-03-08 12:35:36 +00:00
|
|
|
|
2020-04-09 14:03:09 +00:00
|
|
|
pub fn add_keys(&mut self, ty: &str, keys: &str) {
|
|
|
|
let all_keys = match self.types.get_mut(ty) {
|
2020-05-15 02:08:37 +00:00
|
|
|
Some(MetaType::Object { keys: all_keys, .. }) => all_keys,
|
|
|
|
Some(MetaType::Interface { keys: all_keys, .. }) => all_keys,
|
2020-04-09 14:03:09 +00:00
|
|
|
_ => return,
|
|
|
|
};
|
|
|
|
if let Some(all_keys) = all_keys {
|
|
|
|
all_keys.push(keys.to_string());
|
|
|
|
} else {
|
|
|
|
*all_keys = Some(vec![keys.to_string()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
pub fn concrete_type_by_name(&self, type_name: &str) -> Option<&MetaType> {
|
|
|
|
self.types.get(MetaTypeName::concrete_typename(type_name))
|
2020-03-08 12:35:36 +00:00
|
|
|
}
|
2020-03-14 03:46:20 +00:00
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
pub fn concrete_type_by_parsed_type(&self, query_type: &ParsedType) -> Option<&MetaType> {
|
2020-09-06 05:38:31 +00:00
|
|
|
match &query_type.base {
|
|
|
|
ParsedBaseType::Named(name) => self.types.get(name.as_str()),
|
|
|
|
ParsedBaseType::List(ty) => self.concrete_type_by_parsed_type(ty),
|
2020-03-14 03:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-09 14:03:09 +00:00
|
|
|
|
2020-06-02 00:49:27 +00:00
|
|
|
pub(crate) fn has_entities(&self) -> bool {
|
2020-04-09 14:03:09 +00:00
|
|
|
self.types.values().any(|ty| match ty {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Object {
|
2020-04-09 14:03:09 +00:00
|
|
|
keys: Some(keys), ..
|
|
|
|
} => !keys.is_empty(),
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Interface {
|
2020-04-09 14:03:09 +00:00
|
|
|
keys: Some(keys), ..
|
|
|
|
} => !keys.is_empty(),
|
|
|
|
_ => false,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_entity_type(&mut self) {
|
|
|
|
let possible_types = self
|
|
|
|
.types
|
|
|
|
.values()
|
|
|
|
.filter_map(|ty| match ty {
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Object {
|
2020-04-09 14:03:09 +00:00
|
|
|
name,
|
|
|
|
keys: Some(keys),
|
|
|
|
..
|
|
|
|
} if !keys.is_empty() => Some(name.clone()),
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Interface {
|
2020-04-09 14:03:09 +00:00
|
|
|
name,
|
|
|
|
keys: Some(keys),
|
|
|
|
..
|
|
|
|
} if !keys.is_empty() => Some(name.clone()),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
self.types.insert(
|
|
|
|
"_Entity".to_string(),
|
2020-05-15 02:08:37 +00:00
|
|
|
MetaType::Union {
|
2020-04-09 14:03:09 +00:00
|
|
|
name: "_Entity".to_string(),
|
|
|
|
description: None,
|
|
|
|
possible_types,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2020-09-23 00:04:00 +00:00
|
|
|
|
|
|
|
pub(crate) fn create_federation_types(&mut self) {
|
|
|
|
Any::create_type_info(self);
|
|
|
|
|
|
|
|
self.types.insert(
|
|
|
|
"_Service".to_string(),
|
|
|
|
MetaType::Object {
|
|
|
|
name: "_Service".to_string(),
|
|
|
|
description: None,
|
|
|
|
fields: {
|
|
|
|
let mut fields = IndexMap::new();
|
|
|
|
fields.insert(
|
|
|
|
"sdl".to_string(),
|
|
|
|
MetaField {
|
|
|
|
name: "sdl".to_string(),
|
|
|
|
description: None,
|
|
|
|
args: Default::default(),
|
|
|
|
ty: "String".to_string(),
|
|
|
|
deprecation: None,
|
|
|
|
cache_control: Default::default(),
|
|
|
|
external: false,
|
|
|
|
requires: None,
|
|
|
|
provides: None,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
fields
|
|
|
|
},
|
|
|
|
cache_control: Default::default(),
|
|
|
|
extends: false,
|
|
|
|
keys: None,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
self.create_entity_type();
|
|
|
|
|
|
|
|
let query_root = self.types.get_mut(&self.query_type).unwrap();
|
|
|
|
if let MetaType::Object { fields, .. } = query_root {
|
|
|
|
fields.insert(
|
|
|
|
"_service".to_string(),
|
|
|
|
MetaField {
|
|
|
|
name: "_service".to_string(),
|
|
|
|
description: None,
|
|
|
|
args: Default::default(),
|
|
|
|
ty: "_Service!".to_string(),
|
|
|
|
deprecation: None,
|
|
|
|
cache_control: Default::default(),
|
|
|
|
external: false,
|
|
|
|
requires: None,
|
|
|
|
provides: None,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
fields.insert(
|
|
|
|
"_entities".to_string(),
|
|
|
|
MetaField {
|
|
|
|
name: "_entities".to_string(),
|
|
|
|
description: None,
|
|
|
|
args: {
|
|
|
|
let mut args = IndexMap::new();
|
|
|
|
args.insert(
|
|
|
|
"representations",
|
|
|
|
MetaInputValue {
|
|
|
|
name: "representations",
|
|
|
|
description: None,
|
|
|
|
ty: "[_Any!]!".to_string(),
|
|
|
|
default_value: None,
|
|
|
|
validator: None,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
args
|
|
|
|
},
|
|
|
|
ty: "[_Entity]!".to_string(),
|
|
|
|
deprecation: None,
|
|
|
|
cache_control: Default::default(),
|
|
|
|
external: false,
|
|
|
|
requires: None,
|
|
|
|
provides: None,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-05-18 03:24:27 +00:00
|
|
|
}
|