Csy817 7 rokov pred
rodič
commit
3774d29030

+ 1 - 1
src/components/common/graphql/Graphql.jsx

@@ -11,7 +11,7 @@ class Graphql extends Component {
     this.state = {
       //api: 'http://service-ci2tk8iu-1254337200.ap-guangzhou.apigateway.myqcloud.com/release/graphql',
       // 便于开发调试,请删除并换成上面
-      api: 'http://service-eucrnpse-1254337200.ap-guangzhou.apigateway.myqcloud.com/release/graphql'
+      api: 'http://localhost:3000/graphql'
     }
   };
 

+ 2 - 2
src/components/common/schema/Schema.jsx

@@ -19,7 +19,7 @@ class Schema extends Component {
         this.state = {
             currentSchema: '',
             currentTable: '',
-            schemaID: 'schema_1542089023472_19873755',
+            schemaID: 'schema_1542175090046_77378701',
             userID: 'xy_1'
         };
     }
@@ -63,6 +63,7 @@ class Schema extends Component {
                                     currentTableIndex={-2}
                                     columns={[]}
                                     remark=''
+                                    userID={this.state.userID}
                                     schemaID={this.state.schemaID}
                                 /> :
                                 <Query query={SHOW_TABLE}
@@ -119,7 +120,6 @@ class AddSchemaInput extends Component {
                 mutation={ADD_SCHEMA}
                 update={(cache, {data: {create_schema}}) => {
                     let data = cache.readQuery({query: SHOW_SCHEMA, variables: {user_id: userID}});
-
                     data.schema_by_props.push(create_schema);
                     cache.writeQuery({
                         query: SHOW_SCHEMA,

+ 17 - 9
src/components/common/schema/change/SchemaChange.jsx

@@ -174,13 +174,13 @@ class SchemaChange extends Component {
                     />
                     {
                         // undefined的时候 上层未传进来 currentTable === 'add',为的是输入框内不默认显示 add
-                        this.state.currentTable === ''? '' : this.state.currentTable === undefined ? '' :
-                        <DeleteTableButton
-                            currentTable={this.state.currentTable}
-                            currentTableIndex={this.props.currentTableIndex}
-                            schemaID={this.props.schemaID}
-                            userID={this.props.userID}
-                        />
+                        this.state.currentTable === '' ? '' : this.state.currentTable === undefined ? '' :
+                            <DeleteTableButton
+                                currentTable={this.state.currentTable}
+                                currentTableIndex={this.props.currentTableIndex}
+                                schemaID={this.props.schemaID}
+                                userID={this.props.userID}
+                            />
                     }
 
                 </div>
@@ -224,12 +224,19 @@ class UpdateTableButton extends Component {
                                         query: SHOW_TABLE,
                                         variables: {schema_id: schemaID}
                                     });
+
                                     data.schema_by_id = update_schema;
 
+                                    if (update_schema === null) {
+                                        console.log('你是否忘记了修改 Schenma 组件中的 this.state.schemaID? ');
+                                        console.log('所以报错 : TypeError: Cannot read property "schemaName" of null');
+                                    }
+
                                     let showSchemaData = cache.readQuery({
                                         query: SHOW_SCHEMA,
                                         variables: {user_id: userID}
                                     });
+
                                     let index = showSchemaData.schema_by_props.findIndex(obj => obj.schemaName === update_schema.schemaName);
                                     showSchemaData.schema_by_props.splice(index, 1, update_schema);
 
@@ -245,6 +252,7 @@ class UpdateTableButton extends Component {
                                             showSchemaData
                                         }
                                     );
+
                                 }}
                             >
 
@@ -344,7 +352,7 @@ class DeleteTableButton extends Component {
                                     // console.log('targetSchemaIndex', targetSchemaIndex);
                                     let targetTables = JSON.parse(schemas[targetSchemaIndex].schemaData);
                                     // console.log('targetTables', targetTables);
-                                    let targetTableIndex = targetTables.findIndex(obj=> obj.name===this.props.currentTable);
+                                    let targetTableIndex = targetTables.findIndex(obj => obj.name === this.props.currentTable);
                                     // console.log('targetTableIndex', targetTableIndex);
                                     targetTables.splice(targetTableIndex, 1);
                                     // console.log('targetTablesAfterDelete', targetTables);
@@ -385,7 +393,7 @@ class DeleteTableButton extends Component {
                                     if (index === -2) {
                                         console.log('初始页面')
                                     } else if (index === -1) {
-                                        console.log('进行了一次删除操作 或 未知错误,数据库信息不匹配');
+                                        console.log('进行了一次删除操作 或 数据库信息不匹配');
                                     } else {
                                         schemaCols.splice(index, 1);
                                     }

+ 2 - 2
src/components/common/schema/gql.js

@@ -1,6 +1,6 @@
 import gql from "graphql-tag";
 const SHOW_SCHEMA = gql`
-            query SCHEMA($user_id: String) {
+            query SCHEMA($user_id: ID) {
                 schema_by_props(user_id: $user_id) {
                     schemaData
                     schemaName
@@ -10,7 +10,7 @@ const SHOW_SCHEMA = gql`
         `;
 
 const ADD_SCHEMA = gql`
-            mutation SCHEMA($id: ID!, $user_id: String!, $schemaName: String!, $schemaData: String!, $createdAt: String, $updatedAt: String, $schemaState: String) {
+            mutation SCHEMA($id: ID!, $user_id: ID!, $schemaName: String!, $schemaData: String!, $createdAt: String, $updatedAt: String, $schemaState: String) {
                 create_schema(
                     id: $id,
                     user_id: $user_id,