stvkoch / graphqlizejs Goto Github PK
View Code? Open in Web Editor NEWGenerate data types and resolvers from models of sequelizejs
License: MIT License
Generate data types and resolvers from models of sequelizejs
License: MIT License
Taking advantage of Sequelizejs hooks to generate 'subscriptions' data type and resolvers from models that have enabled the options:
gqSubscriptionCreate: true,
gqSubscriptionUpdate: true,
gqSubscriptionDelete: true
Before the start generate the schema, build an object structure, test it and generate the schema from this object instead of look direct over sequelize models.
{
"scalars": [],
"inputs": {},
"types": {
"Query": [],
"Mutation": [],
"Subscription": [],
"category": [
{
"name": "id",
"type": {
"name": "ID",
"allowNull": false,
"collection": false
},
"args": [
{
"name": "_where",
"type": {
"name": "_inputWhereId"
}
}
]
}
]
}
Hi there,
First and foremost, thank you for your work. I really appreciate it.
Add support to the JSON DataType either by a) adding it to the Object of types mapSequelizeToGraphql
in types.js
, or b) removing the absolute
switch you pass to mapTypes()
in schemas.js
, in the body of generateInputOperators()
.
In some of my models I need to use JSON fields. According to the sequelize docs the JSON data type is supported.
I tried to check if my models would work with your library, so I took the code from your example folder and tried it along with my models; then got this error:
SyntaxError: Syntax Error: Expected Name, found ":". (99:3)
97 | input _inputOperator {
98 | eq:
> 99 | ne:
| ^
100 | gte:
101 | gt:
102 | lte:
at e (/home/chirvo/sequelize2/node_modules/prettier/parser-graphql.js:1:319)
I know that's a sequelize error, so I started tracing the bug. Long story short, it took me to schemas.js
, function generateInputOperators()
. In it, you import mapTypes()
from types.js
and pass it a switch for it to return exactly a value of a existing key in an object constant mapSequelizeToGraphql
. declared in the same types.js
. Because of this, when you pass JSON as a datatype, the returned value is an empty string.
Now the possible solutions I propose are quite simplistic, and since I haven't dig deep enough in your code they may prove not viable, but here they are anyway: Either add the JSON
datatype to the mapSequelizeToGraphql
, or remove the absolute
switch from the mapTypes
call in generateInputOperators
. I saw that the only place you call it using the switch is right there; other calls to the same function are not using the switch. Probably the later one may introduce bugs, or break any edge cases you foresaw that I didn't.
If you want me to do a PR with any of these proposed solution let me know.
Thanks!
EDIT: Formatting.
Datetime values is returning a non sense integer that even it's not a timestamp.
v0.3.5 version fix it adding de scalar type date/datetime/time where will convert the datetime values to right scalar type.
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.