bradleyboy / tuql Goto Github PK
View Code? Open in Web Editor NEWAutomatically create a GraphQL server from a SQLite database or a SQL file
License: MIT License
Automatically create a GraphQL server from a SQLite database or a SQL file
License: MIT License
Basically, I have table field ends with "_id", but there is no table related to that field. So is there any way to not parsing that field please? Currently what I can only do is rename that field.
Error message is below:
(node:724) UnhandledPromiseRejectionWarning: Error: Model with tweets does not exist
at findModelKey (node_modules/tuql/dist/utils/index.js:57:9)
at node_modules/tuql/dist/builders/schema.js:107:47
at Array.forEach (<anonymous>)
at node_modules/tuql/dist/builders/schema.js:100:18
(node:724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Thanks for your work!
If the foreign key column of a hasMany relationship has a unique index, we could set it to hasOne instead.
For databases not fitting the convention exactly, we can try to use foreign keys to map the relationships. Would be great if tuql worked with chinook out of the box:
I am using Sqlite3 3.0.16 and am receiving this error on a very simple test database
> Reading schema from database.sqlite
(node:10397) UnhandledPromiseRejectionWarning: Error: Query fields must be an object with field names as keys or a function which returns such an object.
at invariant (/Users/mikee/.config/yarn/global/node_modules/graphql/jsutils/invariant.js:18:11)
at defineFieldMap (/Users/mikee/.config/yarn/global/node_modules/graphql/type/definition.js:353:54)
at GraphQLObjectType.getFields (/Users/mikee/.config/yarn/global/node_modules/graphql/type/definition.js:310:44)
at typeMapReducer (/Users/mikee/.config/yarn/global/node_modules/graphql/type/schema.js:208:25)
at Array.reduce (<anonymous>)
at new GraphQLSchema (/Users/mikee/.config/yarn/global/node_modules/graphql/type/schema.js:97:34)
at Promise (/Users/mikee/.config/yarn/global/node_modules/tuql/dist/builders/schema.js:243:13)
at <anonymous>
(node:10397) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10397) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Mutations support is happy path only right now, needs better error handling.
Would not be a tall order to setup some default mutations to create/update/delete things. Also, should wire up mutations to associate objects when associations are found.
tuql --schema
perhaps? would dump out the raw string representation of the schema that could be piped to a file or whatever
Could you add the topic automatic-api
to your repository? Software that automatically exposes APIs to databases type isn't well-cataloged. (There didn't even seem to be a list on GitHub, so I started one.) It will be easier to discover if there is a standard GitHub topic, and automatic-api
seems as good a candidate as any. Three projects already use it.
I run this on terminal:
$ tuql --db sqlite/dbfile.db --port 8888
> Reading schema from /home/eggplants/prog/sqlite/dbfile.db
(node:572077) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined
at /usr/local/share/.config/yarn/global/node_modules/tuql/dist/builders/schema.js:151:72
at Array.forEach (<anonymous>)
at fields (/usr/local/share/.config/yarn/global/node_modules/tuql/dist/builders/schema.js:150:39)
at resolveThunk (/usr/local/share/.config/yarn/global/node_modules/graphql/type/definition.js:438:40)
at defineFieldMap (/usr/local/share/.config/yarn/global/node_modules/graphql/type/definition.js:625:18)
at GraphQLObjectType.getFields (/usr/local/share/.config/yarn/global/node_modules/graphql/type/definition.js:579:27)
at typeMapReducer (/usr/local/share/.config/yarn/global/node_modules/graphql/type/schema.js:280:78)
at typeMapReducer (/usr/local/share/.config/yarn/global/node_modules/graphql/type/schema.js:286:20)
at Array.reduce (<anonymous>)
at new GraphQLSchema (/usr/local/share/.config/yarn/global/node_modules/graphql/type/schema.js:145:28)
at /usr/local/share/.config/yarn/global/node_modules/tuql/dist/builders/schema.js:246:13
(node:572077) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:572077) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
$ yarn info tuql|grep version:
version: '1.7.0',
Heya,
I'm interested in using tuql with litestream, but they don't play nice atm.
Extending the query in schema.js that excludes sqlite_%
tables to exclude _litestream_%
tables fixes it up.
A) Are ya interested in a PR that adds the ability to exclude other tables?
B) If so, any preference in how that's implemented?
Thanks for the nifty tool!
Because of a different Issue (#21) I was forced to install a new version of sqlite3, which is now 4.0.1.
I am getting this error:
alexa@DESKTOP-6C4V66Q C:\Users\alexa\test-tuql
$ yarn tuql kapla.sqlite --graphiql
yarn run v1.7.0
$ C:\Users\alexa\test-tuql\node_modules\.bin\tuql kapla.sqlite --graphiql
> Reading schema from database.sqlite
(node:16452) UnhandledPromiseRejectionWarning: Error: Query fields must be an object with field names as keys or a function which returns such an object.
at invariant (C:\Users\alexa\test-tuql\node_modules\graphql\jsutils\invariant.js:18:11)
at defineFieldMap (C:\Users\alexa\test-tuql\node_modules\graphql\type\definition.js:353:54)
at GraphQLObjectType.getFields (C:\Users\alexa\test-tuql\node_modules\graphql\type\definition.js:310:44)
at typeMapReducer (C:\Users\alexa\test-tuql\node_modules\graphql\type\schema.js:208:25)
at Array.reduce (<anonymous>)
at new GraphQLSchema (C:\Users\alexa\test-tuql\node_modules\graphql\type\schema.js:97:34)
at Promise (C:\Users\alexa\test-tuql\node_modules\tuql\dist\builders\schema.js:243:13)
Could it be that sqlite3 is only supported in major version 3?
The actual database is in sqlite version 3.22.0.
I'd like to import the lib from my js/ts file, with my own logic, and start the server from there like:
import { createServer } from 'tuql'
Should be able to provide a sql file and it will create an in memory sqlite db
Thank you for this awesome app, tu-ql is really cool
When trying to perform a search on the name field in "Task" model, I tried the SequelizeJSON format as recommended:
QUERY:
query($where: SequelizeJSON) {
tasks(where: $where) {
name
}
}
VARIABLES:
{
"where": "{\"name\": {\"like\": \"Tas%\"}}"
}
But an error is returned:
"errors": [
{
"message": "Invalid value { '$like': 'Tas%' }",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"tasks"
]
}
Any example / best practices to share?
Thanks a lot
indexeddb is meant to be SQLite replacement for web, it's literally a built-in SQLite, with the same types, etc. And I'm interested if this use-case was considered with tuql.
If you'd ask: "why the hell you need GraphQL layer for indexeddb", - I'd answer that it opens interesting capabilities of switching between local/remote queries, while just syncing the storage in background.
Is there a fundamental problem preventing this?
It says not to use it in production with authorization issues, but what if I just use it on backend so as to avoid having to learn joins and unions and etc?
any chance you could update this to work with this version of sqlite? My project is already reliant on that version and I'm not seeing anyway to ignore the dependency with npm (like one would do in JVM world) since it is a regular dependency and not a dev dependency. I'm also getting a bunch of node-gyp errors when just trying to let npm install -g tuql
do its thing:
% npm install -g tuql
npm WARN deprecated [email protected]: Please update to v6 or higher! A migration guide can be found here: https://sequelize.org/v6/manual/upgrade-to-v6.html
npm WARN deprecated [email protected]: This package is no longer maintained. We recommend using `graphql-http` instead. Please consult the migration document https://github.com/graphql/graphql-http#migrating-express-grpahql.
npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
/Users/jonathan/.nvm/versions/node/v20.6.0/bin/tuql -> /Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/dist/bin/index.js
> [email protected] install /Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/node-v115-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v115 ABI, unknown) (falling back to source compile with node-gyp)
gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'
gyp ERR! stack at createConfigFile (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:118:21)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:85:9
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:30:20
gyp ERR! stack at FSReqCallback.oncomplete (node:fs:189:23)
gyp ERR! System Darwin 20.6.0
gyp ERR! command "/Users/jonathan/.nvm/versions/node/v20.6.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3/lib/binding/node-v115-darwin-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3/lib/binding/node-v115-darwin-x64" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v115"
gyp ERR! cwd /Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3
gyp ERR! node -v v20.6.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! This is a bug in `node-gyp`.
gyp ERR! Try to update node-gyp and file an Issue if it does not help:
gyp ERR! <https://github.com/nodejs/node-gyp/issues>
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/Users/jonathan/.nvm/versions/node/v20.6.0/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3/lib/binding/node-v115-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3/lib/binding/node-v115-darwin-x64 --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v115' (7)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (node:events:514:28)
node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1105:16)
node-pre-gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:305:5)
node-pre-gyp ERR! System Darwin 20.6.0
node-pre-gyp ERR! command "/Users/jonathan/.nvm/versions/node/v20.6.0/bin/node" "/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3
node-pre-gyp ERR! node -v v20.6.0
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok
Failed to execute '/Users/jonathan/.nvm/versions/node/v20.6.0/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3/lib/binding/node-v115-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/jonathan/.nvm/versions/node/v20.6.0/lib/node_modules/tuql/node_modules/sqlite3/lib/binding/node-v115-darwin-x64 --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v115' (7)
npm WARN [email protected] requires a peer of graphql-relay@^0.4.2 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/jonathan/.npm/_logs/2023-09-16T02_04_19_364Z-debug.log
Hey @bradleyboy, this is a a very cool module for getting things up and running quickly.
I have a quick question - Is it possible to scaffold/create an actual server (similar to: https://github.com/rexxars/sql-to-graphql) by providing something similar to --output-dir when running tuql initially? Thanks!
Worth a try? https://github.com/mickhansen/dataloader-sequelize
Hi, first of all just want to say this is an amazing tool, it's really just too cool :P
Especially because I understand that tuql generates the GraphQL schema automatically from the sqlite DB. But does it mean that that is the reason why the it's impossible to use GraphQL filter
? Because I'm getting this issue trying to use it:
{
"errors": [
{
"message": "Unknown argument \"filter\" on field \"events\" of type \"Query\".",
"locations": [
{
"line": 35,
"column": 10
}
]
}
]
}
For this query:
{
events(filter: { userInfoType: 0 }) {
userInfoLog
}
}
In addition, I tried to use where
, which is available, with OR
syntax:
{
events( where: { OR: [{userInfoType: 0}, {userInfoType: 1}]}) {
userInfoLog
}
}
But then I'm getting the following error, even though 0 is a valid value for UserInfo_Type in the DB:
{
"errors": [
{
"message": "Invalid value { UserInfo_Type: 0 }",
"locations": [
{
"line": 35,
"column": 2
}
],
"path": [
"events"
]
}
],
"data": {
"events": null
}
}
I am new to GraphQL. Am I doing something wrong?
lowercase the first letter of field names
Trying to figure out this error.
/usr/local/lib/node_modules/tuql/dist/utils/index.js:57
throw Error(`Model with ${key} does not exist`);
^
Error: Model with devices does not exist
at findModelKey (/usr/local/lib/node_modules/tuql/dist/utils/index.js:57:9)
at /usr/local/lib/node_modules/tuql/dist/builders/schema.js:107:47
at Array.forEach (<anonymous>)
at /usr/local/lib/node_modules/tuql/dist/builders/schema.js:100:18
This is from
Line 42 in 5e5c09a
Here is a small sample of my simulated database:
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE cybermen ( id INTEGER PRIMARY KEY AUTOINCREMENT, cybermen_id TEXT, time INTEGER, latitude FLOAT, longitude FLOAT, altitude FLOAT, ll_accuracy FLOAT, alt_accuracy FLOAT, platform TEXT, planet_id TEXT, os_version TEXT, cybermen_model TEXT, device_id TEXT, tracking_enabled INTEGER );
INSERT INTO cybermen VALUES(1,'5505929089744357',1646332890,-58.012831404017347835,41.831462491840198936,54327.88482743823988,78.102049147571591448,60.14073751739705642,'cyberm_os','A-996','COS 10.8.5','T-240','4717defa-a82c-4ac3-9b3d-620dc247fb3d',1);
CREATE TABLE sentients ( id INTEGER PRIMARY KEY AUTOINCREMENT, sentient_id TEXT, time INTEGER, latitude FLOAT, longitude FLOAT, altitude FLOAT, ll_accuracy FLOAT, alt_accuracy FLOAT, platform TEXT, planet_id TEXT, os_version TEXT, species_id TEXT, device_id TEXT, tracking_enabled INTEGER );
INSERT INTO sentients VALUES(1,'06466350783550256',1646332892,-34.706857617227065305,-177.25406639115001894,3273.0915289905128701,64.153259426315315749,37.280746329670137128,'nano_dna_os','2-362','COS 9.1.6','S-545','a05c3f61-e90a-4219-9f2a-a74c71fd67e8',1);
CREATE TABLE planets ( id INTEGER PRIMARY KEY AUTOINCREMENT, planet_id TEXT, aliases TEXT );
INSERT INTO planets VALUES(1,'A-245','Aglaia');
CREATE TABLE sentient_species ( id INTEGER PRIMARY KEY AUTOINCREMENT, species_id TEXT, aliases TEXT );
INSERT INTO sentient_species VALUES(1,'X-209','Xad');
DELETE FROM sqlite_sequence;
COMMIT;
Any idea whats going on?
Error: Model with devices does not exist
Whats up with a key name of devices? I dont have anything named devices in my db.
const tables
in src/builders/schema.js
, replace const tables = rows.map(({
name
}) => name);
by
const tables = rows.map(({
name
}) => name).filter((name) => !filter_django_tables.test(name));
where filter_django_tables
is defined as:
const filter_django_tables = new RegExp('^(auth|django)_');
appname_tablename
where appname
is the name of a Django application (a Django based backend consists of multiple applications). ManyToMany fields are implemented using intermediary join tables and the rules for building their names can be complicated due to table name length limitations by some database backends.I am using:
I tried to install tuql:
alexa@DESKTOP-6C4V66Q C:\Users\alexa\test-tuql
$ npm i --save sqlite3
> [email protected] install C:\Users\alexa\test-tuql\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build
[sqlite3] Success: "C:\Users\alexa\test-tuql\node_modules\sqlite3\lib\binding\node-v64-win32-x64\node_sqlite3.node" is installed via remote
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
+ [email protected]
added 68 packages from 48 contributors in 8.057s
[+] no known vulnerabilities found [97 packages audited]
alexa@DESKTOP-6C4V66Q C:\Users\alexa\test-tuql
$ npm i -s tuql
Die Projekte in dieser Projektmappe werden nacheinander erstellt. Um eine parallele Erstellung zu ermöglichen, müssen Sie den Schalter "/m" hinzufügen.
unpack_sqlite_dep
sqlite3.c
win_delay_load_hook.cc
sqlite3.vcxproj -> C:\Users\alexa\test-tuql\node_modules\tuql\node_modules\sqlite3\build\Release\\sqlite3.lib
database.cc
node_sqlite3.cc
statement.cc
win_delay_load_hook.cc
c:\users\alexa\test-tuql\node_modules\tuql\node_modules\nan\nan_maybe_43_inl.h(112): error C2039: 'ForceSet': is not a member of 'v8::Object' (compiling source file ..\src\statement.cc) [C:\Users\alexa\test-tuql\node_modules\tuql\node_modu
les\sqlite3\build\node_sqlite3.vcxproj]
It did not work without installing sqlite3 first. So that is what I decided to do.
I did see that tuql has an own dependency on sqlite3 in Version 3.1.13.
So I tried to install sqlite3 v3.1.13 directly and got this:
alexa@DESKTOP-6C4V66Q C:\Users\alexa\test-tuql
$ npm i --save [email protected]
> [email protected] install C:\Users\alexa\test-tuql\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build
node-pre-gyp ERR! Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v3.1.13/node-v64-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v64 ABI) (falling back to source compile with node-gyp)
Die Projekte in dieser Projektmappe werden nacheinander erstellt. Um eine parallele Erstellung zu ermöglichen, müssen Sie den Schalter "/m" hinzufügen.
unpack_sqlite_dep
sqlite3.c
win_delay_load_hook.cc
sqlite3.vcxproj -> C:\Users\alexa\test-tuql\node_modules\sqlite3\build\Release\\sqlite3.lib
database.cc
node_sqlite3.cc
statement.cc
win_delay_load_hook.cc
c:\users\alexa\test-tuql\node_modules\nan\nan_maybe_43_inl.h(112): error C2039: 'ForceSet': is not a member of 'v8::Object' (compiling source file ..\src\statement.cc) [C:\Users\alexa\test-tuql\node_modules\sqlite3\build\node_sqlite3.vcxpr oj]
So it seems that for some reason building sqlite3 on Windows errors out. But this only happens because tuql tries to install a version of sqlite3 for which there exists no prepared binary.
If this interpretation is correct, it would be of great help to Windows users if you could update the sqlite3-dependency to a recent version.
Right now this produces offset/limit support, but GraphQL recommends using a type to represent the edge + pageInfo. See:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.