Skip to content

add partly Mysql support #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

add partly Mysql support #48

wants to merge 21 commits into from

Conversation

p-alik
Copy link
Contributor

@p-alik p-alik commented May 15, 2020

This PR doesn't solve the issue #3 entirely. It doesn't contain implementation of insert mutation for Mysql. Consequently wundergraph_example doesn't support Mysql also

Alexei Pastuchov and others added 9 commits April 22, 2020 11:31
Add corresponding feature flags to the wundergraph_derive, wundergraph and wundergraph_cli crate
This requires some manual `HandleInsert` + `HandleBatchInsert` impls
because the default provided one only works with integer primary
keys, because there is no way to generally receive the last inserted
primary key value using mysql.
Interestingly we cannot derive `Insertable` then anymore because of
an error about conflicting impls with the wild card impl in
wundergraph itself. I think that's because rustc will not use
associated types to see if an impl actual is conflicting or not.
Copy link
Owner

@weiznich weiznich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this 👍

The changes itself are looking fine, but we should find some solution for HandleInsert/HandleBatchInsert. I'm fine with supporting only integer primary keys there by default and requiring manual implementations for everyone else, as long as it is documented properly.
Additionally I think that wundergraph_cli does require some additions to support mysql.

To fix the CI you need to run rustfmt and rebase the change to the latest master (as it contains another CI fix).

if select.argument("limit").is_some() {
Ok(q)
} else {
Ok(<_ as LimitDsl>::limit(q, std::i64::MAX))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small comment why this is necessary would be nice, maybe just link the relevant mysql documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put diesel's comment there

@@ -24,5 +24,6 @@ serde_json = "1"

[features]
default = ["postgres", "sqlite"]
sqlite = ["diesel/sqlite"]
mysql = ["diesel/mysql"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no other changes required to get wundergraph_cli working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've to prove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • cargo run --features mysql --no-default-features -- print-schema mysql://**@localhost/wundergraph runs withot any warnings (after e3c50f4)
  • print_schema::tests::round_trip test requires Mysql insert migration.
  • print_schema::tests::infer_schema fails with
Snapshot file: wundergraph_cli/src/print_schema/snapshots/tests__infer_schema.snap
Snapshot: infer_schema
Source: wundergraph_cli/src/print_schema/mod.rs:178
-old snapshot
+new results
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
&s
────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    2     2 │ use wundergraph::scalar::WundergraphScalarValue;
    3     3 │ use wundergraph::WundergraphEntity;
    4     4 │
    5     5 │ table! {
    6       │-    infer_test.comments (id) {
    7       │-        id -> Int4,
    8       │-        post -> Nullable<Int4>,
    9       │-        commenter -> Nullable<Int4>,
          6 │+    comments (id) {
          7 │+        id -> Integer,
          8 │+        post -> Nullable<Integer>,
          9 │+        commenter -> Nullable<Integer>,
   10    10 │         content -> Text,
   11    11 │     }
   12    12 │ }
   13    13 │
   14    14 │ table! {
   15       │-    infer_test.posts (id) {
   16       │-        id -> Int4,
   17       │-        author -> Nullable<Int4>,
         15 │+    posts (id) {
         16 │+        id -> Integer,
         17 │+        author -> Nullable<Integer>,
   18    18 │         title -> Text,
   19       │-        datetime -> Nullable<Timestamp>,
         19 │+        datetime -> Timestamp,
   20    20 │         content -> Nullable<Text>,
   21    21 │     }
   22    22 │ }
   23    23 │
   24    24 │ table! {
   25       │-    infer_test.users (id) {
   26       │-        id -> Int4,
         25 │+    users (id) {
         26 │+        id -> Integer,
   27    27 │         name -> Text,
   28    28 │     }
   29    29 │ }
   30    30 │
   31    31 │ allow_tables_to_appear_in_same_query!(
   39    39 │ #[table_name = "comments"]
   40    40 │ #[primary_key(id)]
   41    41 │ pub struct Comment {
   42    42 │     id: i32,
   43       │-    post: Option<HasOne<i32, Post>>,
   44       │-    commenter: Option<HasOne<i32, User>>,
         43 │+    post: Option<i32>,
         44 │+    commenter: Option<i32>,
   45    45 │     content: String,
   46    46 │ }
   47    47 │
   48    48 │ #[derive(Clone, Debug, Identifiable, WundergraphEntity)]
   49    49 │ #[table_name = "posts"]
   50    50 │ #[primary_key(id)]
   51    51 │ pub struct Post {
   52    52 │     id: i32,
   53       │-    author: Option<HasOne<i32, User>>,
         53 │+    author: Option<i32>,
   54    54 │     title: String,
   55       │-    datetime: Option<chrono::naive::NaiveDateTime>,
         55 │+    datetime: chrono::naive::NaiveDateTime,
   56    56 │     content: Option<String>,
   57       │-    comments: HasMany<Comment, comments::post>,
   58    57 │ }
   59    58 │
   60    59 │ #[derive(Clone, Debug, Identifiable, WundergraphEntity)]
   61    60 │ #[table_name = "users"]
   62    61 │ #[primary_key(id)]
   63    62 │ pub struct User {
   64    63 │     id: i32,
   65    64 │     name: String,
   66       │-    comments: HasMany<Comment, comments::commenter>,
   67       │-    posts: HasMany<Post, posts::author>,
   68    65 │ }
   69    66 │
   70    67 │
   71    68 │
   72    69 │ wundergraph::query_object!{
   81    78 │ #[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
   82    79 │ #[graphql(scalar = "WundergraphScalarValue")]
   83    80 │ #[table_name = "comments"]
   84    81 │ pub struct NewComment {
         82 │+    id: i32,
   85    83 │     post: Option<i32>,
   86    84 │     commenter: Option<i32>,
   87    85 │     content: String,
   88    86 │ }
   89    87 │
  101    99 │ #[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
  102   100 │ #[graphql(scalar = "WundergraphScalarValue")]
  103   101 │ #[table_name = "posts"]
  104   102 │ pub struct NewPost {
        103 │+    id: i32,
  105   104 │     author: Option<i32>,
  106   105 │     title: String,
  107       │-    datetime: Option<chrono::naive::NaiveDateTime>,
  108   106 │     content: Option<String>,
  109   107 │ }
  110   108 │
  111   109 │ #[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
  112   110 │ #[graphql(scalar = "WundergraphScalarValue")]
  115   113 │ pub struct PostChangeset {
  116   114 │     id: i32,
  117   115 │     author: Option<i32>,
  118   116 │     title: String,
  119       │-    datetime: Option<chrono::naive::NaiveDateTime>,
        117 │+    datetime: chrono::naive::NaiveDateTime,
  120   118 │     content: Option<String>,
  121   119 │ }
  122   120 │
  123   121 │ #[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
  124   122 │ #[graphql(scalar = "WundergraphScalarValue")]
  125   123 │ #[table_name = "users"]
  126   124 │ pub struct NewUser {
        125 │+    id: i32,
  127   126 │     name: String,
  128   127 │ }
  129   128 │
  130   129 │ #[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
  131   130 │ #[graphql(scalar = "WundergraphScalarValue")]
────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
To update snapshots run `cargo insta review`

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically all changes to the model structs here should not happen. That means we need to filter out somehow primary keys for the New* model structs, fix foreign key relations for the query models (HasOne/HasMany and figure out what's wrong with the datetime columns. (Maybe a NOT NULL to much?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a0dc070 filters primary keys explicitly

@p-alik
Copy link
Contributor Author

p-alik commented May 16, 2020

CI fails for sake of MacOs. I'll work through both insert handlers and appropriate MySQL-wundergraph_example.

@weiznich
Copy link
Owner

I've pushed and merged a fix for the CI failure in #49.

@p-alik p-alik force-pushed the issue-3 branch 3 times, most recently from 4d4fb2c to 094d06d Compare May 18, 2020 05:05
@@ -107,6 +110,7 @@ pub struct NewPost {
id: i32,
author: Option<i32>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually NewPost shouldn't contain id.

@@ -17,7 +17,7 @@ diesel = "1.4"

[dev-dependencies]
dotenv = "0.15"
insta = "0.12"
insta = "0.16"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this commit has an impact on snapshot names: your snapshot was named tests__infer_schema.snap, but insta v0.16 seems to look for wundergraph_cli__print_schema__tests__infer_schema.snap

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's totally fine. Just move/regenerate the snapshot files to the new location.

@p-alik p-alik mentioned this pull request Jun 11, 2020
7 tasks
@@ -316,7 +420,7 @@ mod tests {
println!("Started server");

let client = reqwest::Client::new();
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(std::time::Duration::from_secs(5));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 secs was used to run mysql tests locally. But since ci postgres test failed for same reason, I increased the sleep duration globally.

@p-alik
Copy link
Contributor Author

p-alik commented Jul 15, 2020

@weiznich, is there anything I've to do to move forward with this PR?

@weiznich
Copy link
Owner

@p-alik I've been quite busy in real life in the last weeks, so I had unfortunately no time to look into this yet. I will try to find some time on the weekend or next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants