|
| 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 -> Nullable<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<HasOne<i32, Post>>, |
| 48 | + commenter: Option<HasOne<i32, User>>, |
| 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<HasOne<i32, User>>, |
| 58 | + title: String, |
| 59 | + datetime: Option<chrono::naive::NaiveDateTime>, |
| 60 | + content: Option<String>, |
| 61 | + comments: HasMany<Comment, comments::post>, |
| 62 | +} |
| 63 | + |
| 64 | +#[derive(Clone, Debug, Identifiable, WundergraphEntity)] |
| 65 | +#[table_name = "users"] |
| 66 | +#[primary_key(id)] |
| 67 | +pub struct User { |
| 68 | + id: i32, |
| 69 | + name: String, |
| 70 | + comments: HasMany<Comment, comments::commenter>, |
| 71 | + posts: HasMany<Post, posts::author>, |
| 72 | +} |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +wundergraph::query_object!{ |
| 77 | + Query { |
| 78 | + Comment, |
| 79 | + Post, |
| 80 | + User, |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)] |
| 86 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 87 | +#[table_name = "comments"] |
| 88 | +pub struct NewComment { |
| 89 | + post: Option<i32>, |
| 90 | + commenter: Option<i32>, |
| 91 | + content: String, |
| 92 | +} |
| 93 | + |
| 94 | +#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)] |
| 95 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 96 | +#[table_name = "comments"] |
| 97 | +#[primary_key(id)] |
| 98 | +pub struct CommentChangeset { |
| 99 | + id: i32, |
| 100 | + post: Option<i32>, |
| 101 | + commenter: Option<i32>, |
| 102 | + content: String, |
| 103 | +} |
| 104 | + |
| 105 | +#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)] |
| 106 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 107 | +#[table_name = "posts"] |
| 108 | +pub struct NewPost { |
| 109 | + author: Option<i32>, |
| 110 | + title: String, |
| 111 | + datetime: Option<chrono::naive::NaiveDateTime>, |
| 112 | + content: Option<String>, |
| 113 | +} |
| 114 | + |
| 115 | +#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)] |
| 116 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 117 | +#[table_name = "posts"] |
| 118 | +#[primary_key(id)] |
| 119 | +pub struct PostChangeset { |
| 120 | + id: i32, |
| 121 | + author: Option<i32>, |
| 122 | + title: String, |
| 123 | + datetime: Option<chrono::naive::NaiveDateTime>, |
| 124 | + content: Option<String>, |
| 125 | +} |
| 126 | + |
| 127 | +#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)] |
| 128 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 129 | +#[table_name = "users"] |
| 130 | +pub struct NewUser { |
| 131 | + name: String, |
| 132 | +} |
| 133 | + |
| 134 | +#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)] |
| 135 | +#[graphql(scalar = "WundergraphScalarValue")] |
| 136 | +#[table_name = "users"] |
| 137 | +#[primary_key(id)] |
| 138 | +pub struct UserChangeset { |
| 139 | + id: i32, |
| 140 | + name: String, |
| 141 | +} |
| 142 | + |
| 143 | +wundergraph::mutation_object!{ |
| 144 | + Mutation{ |
| 145 | + Comment(insert = NewComment, update = CommentChangeset, ), |
| 146 | + Post(insert = NewPost, update = PostChangeset, ), |
| 147 | + User(insert = NewUser, update = UserChangeset, ), |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | + |
0 commit comments