@raynode/graphql-connector-sequelize
Advanced tools
Comparing version 0.8.0 to 0.8.1
{ | ||
"name": "@raynode/graphql-connector-sequelize", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "", | ||
@@ -62,3 +62,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "67b0925c3f793d6225ba2e89c944053f71948484" | ||
"gitHead": "05f404ccc293e5accb71dea777122a3ff1688fa9" | ||
} |
@@ -23,13 +23,13 @@ import { createBaseSchemaGenerator, createSchema } from '@raynode/graphql-connector' | ||
it('should find the attributes of a Loop', () => { | ||
const result = modelMapper('Loop', models.Loop) | ||
expect(result.attributes).toHaveProperty('id') | ||
expect(result.attributes).toHaveProperty('createdAt') | ||
expect(result.attributes).toHaveProperty('updatedAt') | ||
}) | ||
// it('should find the attributes of a Loop', () => { | ||
// const result = modelMapper('Loop', models.Loop) | ||
// expect(result.attributes).toHaveProperty('id') | ||
// expect(result.attributes).toHaveProperty('createdAt') | ||
// expect(result.attributes).toHaveProperty('updatedAt') | ||
// }) | ||
it('should find the association of a Loop', () => { | ||
const result = modelMapper('Loop', models.Loop) | ||
expect(result.associations).toHaveProperty('next') | ||
}) | ||
// it('should find the association of a Loop', () => { | ||
// const result = modelMapper('Loop', models.Loop) | ||
// expect(result.associations).toHaveProperty('next') | ||
// }) | ||
}) | ||
@@ -247,2 +247,19 @@ | ||
}) | ||
it('should create a bookmark for Paulchen', async () => { | ||
const { data } = await runQuery(`mutation { | ||
createLink(data: { | ||
url: "https://example.com" | ||
title: "Examples" | ||
user: { | ||
nickname: "Paulchen" | ||
} | ||
}) { | ||
id | ||
title | ||
url | ||
user { name nickname } | ||
} | ||
}`) | ||
}) | ||
}) |
@@ -60,3 +60,2 @@ import { AnyModel, createModelMapper, GeneratedModelMapper, Page } from '@raynode/graphql-connector' | ||
export const modelMapper = createModelMapper<DataTypes, Models>((model, addAttribute, addAssociation) => { | ||
@@ -113,3 +112,3 @@ const rawModel: SequelizeModel = model as any | ||
const getModelData = (association, data) => | ||
const getModelData = (association: SequelizeAssociation, data: any) => | ||
findFromModel(association.target, isListAssociation(association), applyParser(association.target, data)) | ||
@@ -116,0 +115,0 @@ |
@@ -0,1 +1,2 @@ | ||
// tslint:disable:no-object-literal-type-assertion | ||
@@ -50,13 +51,15 @@ import { pluralize } from 'inflection' | ||
export const Loop = sequelize.define('Loop', { | ||
export const Link = sequelize.define('Link', { | ||
id, | ||
}) | ||
title: { type: Sequelize.STRING, allowNull: false }, | ||
url: { type: Sequelize.STRING, allowNull: false }, | ||
UserId: { type: Sequelize.UUID, allowNull: true, visible: false }, | ||
} as SequelizeAttributes) | ||
User.hasMany(Post) | ||
Post.belongsTo(User) | ||
Loop.hasOne(Loop, { | ||
as: 'next', | ||
}) | ||
User.hasMany(Link, { as: 'bookmarks', foreignKey: 'UserId', sourceKey: 'id' }) | ||
Link.hasOne(User, { as: 'user', foreignKey: 'id', constraints: false }) | ||
export const models = { User, Loop, Post } | ||
export const models = { User, Link, Post } | ||
@@ -63,0 +66,0 @@ export const initialize = async () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
133113
2320