rexxars / sql-to-graphql

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

Error running the first stage #37

Closed ruslantalpa closed 9 years ago

ruslantalpa commented 9 years ago

When i run by providing each paramerter manually i get

sql2graphql --db "dbname" -u "username" -p "password" -p 5432 -b postgres -o ./app
Unhandled rejection TypeError: undefined is not a function
    at /usr/local/lib/node_modules/sql-to-graphql/steps/find-one-to-many-rels.js:29:17
    at Array.forEach (native)
    at findRelationships (/usr/local/lib/node_modules/sql-to-graphql/steps/find-one-to-many-rels.js:27:22)
    at tasklist.(anonymous function) (/usr/local/lib/node_modules/sql-to-graphql/steps/find-one-to-many-rels.js:13:13)
    at /usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:689:13
    at /usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:239:13
    at /usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:119:13
    at _arrayEach (/usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:91:13)
    at _forEachOf (/usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:118:9)
    at _each (/usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:83:13)
    at async.forEachOf.async.eachOf (/usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:238:9)
    at _parallel (/usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:688:9)
    at Object.async.parallel (/usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:702:9)
    at Object.findOneToManyRelationships [as findOneToManyReferences] (/usr/local/lib/node_modules/sql-to-graphql/steps/find-one-to-many-rels.js:18:11)
    at onTableDataCollected (/usr/local/lib/node_modules/sql-to-graphql/cli.js:139:11)
    at /usr/local/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:697:13

if i runin interactive mode, i get

Knex:Error Pool2 - error: database "undefined" does not exist
Knex:Error Pool2 - error: database "undefined" does not exist

i think i checked the user/pass and they seem to be correct Thanks.

Bulforce commented 9 years ago

try like this: sql2graphql --db=dbname -u=username -p=password ...

or I think you can also use sql2graphql -i

rexxars commented 9 years ago

Couple of things:

1) The aliases for --port and --password differ in case: Port has a capital P while password has a lowercase p. 2) Awkwardly enough, the postgres adapter didn't implement the hasDuplicateValues method. We really need some tests here soon. I've added the method and published as 2.0.7, give that a try and see if it works out any better.

ruslantalpa commented 9 years ago

In interactive mode i get the same error, when specifying all the params, the error changed

Workstation:sqlgraphql ruslantalpa$ sql2graphql --db=dbname -u=username --password "" --port 5432 -b postgres -o ./app
Unhandled rejection error: select count("client_id") as "hasSameValues" from "projects" group by "client_id" having "hasSameValues" > $1 limit $2 - column "hasSameValues" 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 Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)
Unhandled rejection error: select count("project_id") as "hasSameValues" from "tasks" group by "project_id" having "hasSameValues" > $1 limit $2 - column "hasSameValues" 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 Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)

as you can see it read a bit of the structure of the db, to the connection params are correct

luchillo17 commented 7 years ago

It seems in postgresql you can't use the alias inside the having clause, the error in the adapter for that hasSameValues part is in line #L118.

I've tried to deal with it in postgres and it seems that the following works, however i can't find a way to make it work with the pg.having query function since it wraps it in double quote like in the image.

select count("user_id") from "posts" group by "user_id" having count("user_id") > 1 limit 2

image