|
| 1 | +--- |
| 2 | +source: wundergraph_cli/src/print_schema/mod.rs |
| 3 | +expression: "&s" |
| 4 | +--- |
| 5 | +use wundergraph::query_builder::types::{HasMany, HasOne}; |
| 6 | +use wundergraph::scalar::WundergraphScalarValue; |
| 7 | +use wundergraph::WundergraphEntity; |
| 8 | + |
| 9 | +table! { |
| 10 | + comments (id) { |
| 11 | + id -> Integer, |
| 12 | + post -> Nullable<Integer>, |
| 13 | + commenter -> Nullable<Integer>, |
| 14 | + content -> Text, |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +table! { |
| 19 | + posts (id) { |
| 20 | + id -> Integer, |
| 21 | + author -> Nullable<Integer>, |
| 22 | + title -> Text, |
| 23 | + datetime -> Timestamp, |
| 24 | + content -> Nullable<Text>, |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +table! { |
| 29 | + users (id) { |
| 30 | + id -> Integer, |
| 31 | + name -> Text, |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +allow_tables_to_appear_in_same_query!( |
| 36 | + comments, |
| 37 | + posts, |
| 38 | + users, |
| 39 | +); |
| 40 | + |
| 41 | + |
| 42 | +#[derive(Clone, Debug, Identifiable, WundergraphEntity)] |
| 43 | +#[table_name = "comments"] |
| 44 | +#[primary_key(id)] |
| 45 | +pub struct Comment { |
| 46 | + id: i32, |
| 47 | + post: Option<i32>, |
| 48 | + commenter: Option<i32>, |
| 49 | + content: String, |
| 50 | +} |
| 51 | + |
| 52 | +#[derive(Clone, Debug, Identifiable, WundergraphEntity)] |
| 53 | +#[table_name = "posts"] |
| 54 | +#[primary_key(id)] |
| 55 | +pub struct Post { |
| 56 | + id: i32, |
| 57 | + author: Option<i32>, |
| 58 | + title: String, |
| 59 | + datetime: chrono::naive::NaiveDateTime, |
| 60 | + content: Option<String>, |
| 61 | +} |
| 62 | + |
| 63 | +#[derive(Clone, Debug, Identifiable, WundergraphEntity)] |
| 64 | +#[table_name = "users"] |
| 65 | +#[primary_key(id)] |
| 66 | +pub struct User { |
| 67 | + id: i32, |
| 68 | + name: String, |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +wundergraph::query_object!{ |
| 74 | + Query { |
| 75 | + Comment, |
| 76 | + Post, |
| 77 | + User, |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | + |
| 82 | +#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)] |
| 83 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 84 | +#[table_name = "comments"] |
| 85 | +pub struct NewComment { |
| 86 | + id: i32, |
| 87 | + post: Option<i32>, |
| 88 | + commenter: Option<i32>, |
| 89 | + content: String, |
| 90 | +} |
| 91 | + |
| 92 | +#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)] |
| 93 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 94 | +#[table_name = "comments"] |
| 95 | +#[primary_key(id)] |
| 96 | +pub struct CommentChangeset { |
| 97 | + id: i32, |
| 98 | + post: Option<i32>, |
| 99 | + commenter: Option<i32>, |
| 100 | + content: String, |
| 101 | +} |
| 102 | + |
| 103 | +#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)] |
| 104 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 105 | +#[table_name = "posts"] |
| 106 | +pub struct NewPost { |
| 107 | + id: i32, |
| 108 | + author: Option<i32>, |
| 109 | + title: String, |
| 110 | + content: Option<String>, |
| 111 | +} |
| 112 | + |
| 113 | +#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)] |
| 114 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 115 | +#[table_name = "posts"] |
| 116 | +#[primary_key(id)] |
| 117 | +pub struct PostChangeset { |
| 118 | + id: i32, |
| 119 | + author: Option<i32>, |
| 120 | + title: String, |
| 121 | + datetime: chrono::naive::NaiveDateTime, |
| 122 | + content: Option<String>, |
| 123 | +} |
| 124 | + |
| 125 | +#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)] |
| 126 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 127 | +#[table_name = "users"] |
| 128 | +pub struct NewUser { |
| 129 | + id: i32, |
| 130 | + name: String, |
| 131 | +} |
| 132 | + |
| 133 | +#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)] |
| 134 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 135 | +#[table_name = "users"] |
| 136 | +#[primary_key(id)] |
| 137 | +pub struct UserChangeset { |
| 138 | + id: i32, |
| 139 | + name: String, |
| 140 | +} |
| 141 | + |
| 142 | +wundergraph::mutation_object!{ |
| 143 | + Mutation{ |
| 144 | + Comment(insert = NewComment, update = CommentChangeset, ), |
| 145 | + Post(insert = NewPost, update = PostChangeset, ), |
| 146 | + User(insert = NewUser, update = UserChangeset, ), |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | + |
0 commit comments