rexxars / sql-to-graphql

Generate a GraphQL API based on your SQL database structure
MIT License
592 stars 73 forks source link

Getting error "Unhandled rejection Error" when using with mysql #44

Open praseedasathaye opened 7 years ago

praseedasathaye commented 7 years ago

I have a table called blogs in the database blogPost that has below information

mysql> desc blogs; +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | userId | int(11) | NO | | NULL | | | title | varchar(150) | NO | | NULL | | | description | varchar(150) | NO | | NULL | | +-------------+------------------+------+-----+---------+----------------+

sqlToGraphql$ sql2graphql -i ? What kind of database is it? mysql ? What is the hostname of your database server? localhost ? What is the name of the database? blogPost ? What is the database username? root ? What is the database password? **** ? What is the port number of the mysql database? 3306 ? Output path of the application /Users/Projects/sqlToGraphql ? Do you want to use babel + ES6? No ? Do you want a Relay-style GraphQL schema? No ? Select tables to include blogs, users Unhandled rejection Error: ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'field list' at Query.Sequence._packetToError (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14) at Query.ErrorPacket (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/protocol/sequences/Query.js:77:18) at Protocol._parsePacket (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/protocol/Protocol.js:280:23) at Parser.write (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/protocol/Parser.js:75:12) at Protocol.write (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/protocol/Protocol.js:39:16) at Socket. (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/Connection.js:103:28) at emitOne (events.js:96:13) at Socket.emit (events.js:189:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at TCP.onread (net.js:551:20)

at Protocol._enqueue (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/protocol/Protocol.js:141:48)
at Connection.query (/usr/local/lib/node_modules/sql-to-graphql/node_modules/mysql/lib/Connection.js:208:25)
at /usr/local/lib/node_modules/sql-to-graphql/node_modules/knex/lib/dialects/mysql/index.js:92:18
at tryCatcher (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/util.js:26:23)
at Promise._resolveFromResolver (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/promise.js:483:31)
at new Promise (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/promise.js:71:37)
at Client._query (/usr/local/lib/node_modules/sql-to-graphql/node_modules/knex/lib/dialects/mysql/index.js:88:12)
at Client.query (/usr/local/lib/node_modules/sql-to-graphql/node_modules/knex/lib/client.js:127:24)
at Runner.<anonymous> (/usr/local/lib/node_modules/sql-to-graphql/node_modules/knex/lib/runner.js:118:24)
at Runner.tryCatcher (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/util.js:26:23)
at Runner.query (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/method.js:15:34)
at /usr/local/lib/node_modules/sql-to-graphql/node_modules/knex/lib/runner.js:44:21
at /usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/using.js:176:30
at tryCatcher (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/promise.js:510:31)
at Promise._settlePromiseAt (/usr/local/lib/node_modules/sql-to-graphql/node_modules/bluebird/js/main/promise.js:584:18)
amaury1093 commented 7 years ago

I have the same error with postgres. There's no error when selecting a single table, but there's an error with associations (here: one Student has many Educations).

$ sql2graphql --db mydb -b pg -o example -i
? What is the hostname of your database server? localhost
? What is the database username? root
? What is the database password? 
? What is the port number of the undefined database? 5432
? Do you want to use babel + ES6? No
? Do you want a Relay-style GraphQL schema? No
? Select tables to include educations, students
Unhandled rejection error: column "undefined" does not exist
    at Connection.parseE (/usr/local/lib/node_modules/sql-to-graphql/node_modules/pg/lib/connection.js:539:11)
    at Connection.parseMessage (/usr/local/lib/node_modules/sql-to-graphql/node_modules/pg/lib/connection.js:366:17)
    at Socket.<anonymous> (/usr/local/lib/node_modules/sql-to-graphql/node_modules/pg/lib/connection.js:105:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at TCP.onread (net.js:563:20)
selfagency commented 7 years ago
 D/nylon-graphql $ sql2graphql -i
? What kind of database is it? mysql
? What is the hostname of your database server? localhost
? What is the name of the database? nylon
? What is the database username? root
? What is the database password?
? What is the port number of the mysql database? 3306
? Output path of the application ./
? Do you want to use babel + ES6? Yes
? Do you want a Relay-style GraphQL schema? No
? Select tables to include admin_users, article_images, author_socials, authors, categories, categories_hashtags, credits, featured_images, galleries, gallery_images, hashtags, images, pages, posts, posts_tags, records, redirectsUnhandled rejection TypeError: Cannot read property 'originalName' of undefined
    at generateListReferenceField (/Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/steps/generate-types.js:154:105)
    at /Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/steps/generate-types.js:59:25
    at Array.forEach (<anonymous>)
    at generateType (/Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/steps/generate-types.js:58:30)
    at Object.generateTypes (/Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/steps/generate-types.js:32:27)
    at /Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/cli.js:144:28
    at /Users/daniel/.config/yarn/global/node_modules/async/lib/async.js:726:13
    at /Users/daniel/.config/yarn/global/node_modules/async/lib/async.js:52:16
    at done (/Users/daniel/.config/yarn/global/node_modules/async/lib/async.js:246:17)
    at /Users/daniel/.config/yarn/global/node_modules/async/lib/async.js:44:16
    at /Users/daniel/.config/yarn/global/node_modules/async/lib/async.js:723:17
    at /Users/daniel/.config/yarn/global/node_modules/async/lib/async.js:167:37
    at /Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/node_modules/lodash/function/after.js:43:19
    at /Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/steps/find-one-to-many-rels.js:35:24
    at /Users/daniel/.config/yarn/global/node_modules/sql-to-graphql/backends/mysql.js:89:21
    at tryCatcher (/Users/daniel/.config/yarn/global/node_modules/knex/node_modules/bluebird/js/main/util.js:26:23)
^C⏎