|
| 1 | +use super::util; |
| 2 | +use juniper::{EmptyMutation, Executor, GraphQLType}; |
| 3 | + |
| 4 | +#[derive(GraphQLObject)] |
| 5 | +struct SomeType { |
| 6 | + a: bool, |
| 7 | +} |
| 8 | + |
| 9 | +#[derive(Default)] |
| 10 | +struct Context { |
| 11 | + version: Option<String>, |
| 12 | +} |
| 13 | + |
| 14 | +#[derive(Default)] |
| 15 | +struct TheQuery { |
| 16 | + b: bool, |
| 17 | +} |
| 18 | + |
| 19 | +#[juniper::impl_object( |
| 20 | + scalar = juniper::DefaultScalarValue, |
| 21 | + name = "Query", |
| 22 | + description = "Type Description", |
| 23 | + context = Context, |
| 24 | +)] |
| 25 | +impl TheQuery { |
| 26 | + #[graphql(description = "With Self Description")] |
| 27 | + fn with_self(&self) -> bool { |
| 28 | + self.b |
| 29 | + } |
| 30 | + |
| 31 | + fn independent() -> i32 { |
| 32 | + 100 |
| 33 | + } |
| 34 | + |
| 35 | + fn with_executor(exec: &Executor<Context>) -> bool { |
| 36 | + true |
| 37 | + } |
| 38 | + |
| 39 | + fn with_executor_and_self(&self, exec: &Executor<Context>) -> bool { |
| 40 | + true |
| 41 | + } |
| 42 | + |
| 43 | + fn with_context(exec: &Context) -> bool { |
| 44 | + true |
| 45 | + } |
| 46 | + |
| 47 | + fn with_context_and_self(&self, exec: &Context) -> bool { |
| 48 | + true |
| 49 | + } |
| 50 | + |
| 51 | + #[graphql(name = "renamed")] |
| 52 | + fn has_custom_name() -> bool { |
| 53 | + true |
| 54 | + } |
| 55 | + |
| 56 | + #[graphql(description = "attr")] |
| 57 | + fn has_description_attr() -> bool { |
| 58 | + true |
| 59 | + } |
| 60 | + |
| 61 | + /// Doc description |
| 62 | + fn has_description_doc_comment() -> bool { |
| 63 | + true |
| 64 | + } |
| 65 | + |
| 66 | + fn has_argument(arg1: bool) -> bool { |
| 67 | + true |
| 68 | + } |
| 69 | + |
| 70 | + fn has_object_return(&self) -> SomeType { |
| 71 | + SomeType { a: true } |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +#[derive(Default)] |
| 76 | +struct Mutation; |
| 77 | + |
| 78 | +#[juniper::impl_object(context = Context)] |
| 79 | +impl Mutation { |
| 80 | + fn empty() -> bool { |
| 81 | + true |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +#[test] |
| 86 | +fn impl_object_full_introspect() { |
| 87 | + let res = util::run_info_query::<TheQuery, Mutation, Context>("Query"); |
| 88 | + assert_eq!(juniper::graphql_value!({ |
| 89 | + "name": "Query", |
| 90 | + "description": "Type Description", |
| 91 | + "fields": [ |
| 92 | + { |
| 93 | + "name": "withSelf", |
| 94 | + "description": "With Self Description", |
| 95 | + "args": [], |
| 96 | + }, |
| 97 | + { |
| 98 | + "name": "independent", |
| 99 | + "description": None, |
| 100 | + "args": [], |
| 101 | + }, |
| 102 | + { |
| 103 | + "name": "withExecutor", |
| 104 | + "description": None, |
| 105 | + "args": [], |
| 106 | + }, |
| 107 | + { |
| 108 | + "name": "withExecutorAndSelf", |
| 109 | + "description": None, |
| 110 | + "args": [], |
| 111 | + }, |
| 112 | + { |
| 113 | + "name": "withContext", |
| 114 | + "description": None, |
| 115 | + "args": [], |
| 116 | + }, |
| 117 | + { |
| 118 | + "name": "withContextAndSelf", |
| 119 | + "description": None, |
| 120 | + "args": [], |
| 121 | + }, |
| 122 | + { |
| 123 | + "name": "renamed", |
| 124 | + "description": None, |
| 125 | + "args": [], |
| 126 | + }, |
| 127 | + { |
| 128 | + "name": "hasDescriptionAttr", |
| 129 | + "description": "attr", |
| 130 | + "args": [], |
| 131 | + }, |
| 132 | + { |
| 133 | + "name": "hasDescriptionDocComment", |
| 134 | + "description": "Doc description", |
| 135 | + "args": [], |
| 136 | + }, |
| 137 | + { |
| 138 | + "name": "hasArgument", |
| 139 | + "description": None, |
| 140 | + "args": [ |
| 141 | + { |
| 142 | + "name": "arg1", |
| 143 | + "description": None, |
| 144 | + "type": { |
| 145 | + "name": None, |
| 146 | + }, |
| 147 | + } |
| 148 | + ], |
| 149 | + }, |
| 150 | + { |
| 151 | + "name": "hasObjectReturn", |
| 152 | + "description": None, |
| 153 | + "args": [], |
| 154 | + }, |
| 155 | + ] |
| 156 | + })); |
| 157 | +} |
0 commit comments