1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
use std::collections::HashSet;
use crate::{model::__InputValue, registry, Enum, Object};
/// A Directive can be adjacent to many parts of the GraphQL language, a
/// __DirectiveLocation describes one such possible adjacencies.
#[derive(Debug, Enum, Copy, Clone, Eq, PartialEq)]
#[graphql(internal, name = "__DirectiveLocation")]
#[allow(non_camel_case_types)]
pub enum __DirectiveLocation {
/// Location adjacent to a query operation.
QUERY,
/// Location adjacent to a mutation operation.
MUTATION,
/// Location adjacent to a subscription operation.
SUBSCRIPTION,
/// Location adjacent to a field.
FIELD,
/// Location adjacent to a fragment definition.
FRAGMENT_DEFINITION,
/// Location adjacent to a fragment spread.
FRAGMENT_SPREAD,
/// Location adjacent to an inline fragment.
INLINE_FRAGMENT,
/// Location adjacent to a variable definition.
VARIABLE_DEFINITION,
/// Location adjacent to a schema definition.
SCHEMA,
/// Location adjacent to a scalar definition.
SCALAR,
/// Location adjacent to an object type definition.
OBJECT,
/// Location adjacent to a field definition.
FIELD_DEFINITION,
/// Location adjacent to an argument definition.
ARGUMENT_DEFINITION,
/// Location adjacent to an interface definition.
INTERFACE,
/// Location adjacent to a union definition.
UNION,
/// Location adjacent to an enum definition.
ENUM,
/// Location adjacent to an enum value definition.
ENUM_VALUE,
/// Location adjacent to an input object type definition.
INPUT_OBJECT,
/// Location adjacent to an input object field definition.
INPUT_FIELD_DEFINITION,
}
// Traits for compile time checking if location at which directive is called is
// supported by directives definition Would be nice to auto generate traits from
// variants of __DirectiveLocation
#[doc(hidden)]
#[allow(non_camel_case_types)]
pub mod location_traits {
pub trait Directive_At_FIELD_DEFINITION {
fn check() {}
}
pub trait Directive_At_OBJECT {
fn check() {}
}
pub trait Directive_At_INPUT_FIELD_DEFINITION {
fn check() {}
}
pub trait Directive_At_ARGUMENT_DEFINITION {
fn check() {}
}
pub trait Directive_At_INPUT_OBJECT {
fn check() {}
}
pub trait Directive_At_INTERFACE {
fn check() {}
}
pub trait Directive_At_ENUM {
fn check() {}
}
pub trait Directive_At_ENUM_VALUE {
fn check() {}
}
}
pub struct __Directive<'a> {
pub registry: &'a registry::Registry,
pub visible_types: &'a HashSet<&'a str>,
pub directive: &'a registry::MetaDirective,
}
/// A Directive provides a way to describe alternate runtime execution and type
/// validation behavior in a GraphQL document.
///
/// In some cases, you need to provide options to alter GraphQL's execution
/// behavior in ways field arguments will not suffice, such as conditionally
/// including or skipping a field. Directives provide this by describing
/// additional information to the executor.
#[Object(internal, name = "__Directive")]
impl<'a> __Directive<'a> {
#[inline]
async fn name(&self) -> &str {
&self.directive.name
}
#[inline]
async fn description(&self) -> Option<&str> {
self.directive.description.as_deref()
}
#[inline]
async fn locations(&self) -> &Vec<__DirectiveLocation> {
&self.directive.locations
}
async fn args(&self) -> Vec<__InputValue<'a>> {
self.directive
.args
.values()
.map(|input_value| __InputValue {
registry: self.registry,
visible_types: self.visible_types,
input_value,
})
.collect()
}
#[inline]
async fn is_repeatable(&self) -> bool {
self.directive.is_repeatable
}
}