-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
belongsToMany
associations have undefined output type
#92
Comments
Hi Ben, can you provide your models or create relations on some example models so we can test it.
Also which version are you using?
…Sent from my iPhone
On 25 Jan 2024, at 21:12, Ben Weller ***@***.***> wrote:
I've run into an issue regarding belongsToMany relationships. It seems that a type is not generated when there is a join table. This is causing graphcraft to not function using graphql and graphql-http (specifically the express library).
For example:
This is the error: The type of Workorder.WorkorderParts must be Output Type but got: undefined.
We have a Workorder model, a Parts model and a join table, WorkorderParts.
Can anyone provide any guidance as to why this is happening? Is this a known issue or am I just doing something incorrectly?
Thanks in advance.
—
Reply to this email directly, view it on GitHub<#92>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADAUKBWKU5OCBEOIU6ENFC3YQK4DBAVCNFSM6AAAAABCLDMTACVHI2DSMVQWIX3LMV43ASLTON2WKOZSGEYDCMBZGY4TAMA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Wow. Thanks for the quick reply! I'm using v1.2.1 Here are the relevant portions of the least complex models. Here, we're looking at the // models/vendor.js - Vendor model
module.exports = (sequelize, DataTypes) => {
const Vendor = sequelize.define('Vendor', {
name: DataTypes.STRING,
accountNumber: DataTypes.STRING,
website: DataTypes.STRING,
address: DataTypes.STRING,
addressTwo: DataTypes.STRING,
city: DataTypes.STRING,
state: DataTypes.STRING,
postalCode: DataTypes.STRING,
shipOnly: DataTypes.BOOLEAN
}, {})
Vendor.associate = function ({VendorLocation, Contact, Part}) {
//Vendor.hasMany(VendorLocation)
Vendor.belongsToMany(Contact, { through: 'VendorContacts'})
//Vendor.belongsToMany(Part, { through: 'VendorParts', constraints: false})
}
return Vendor
}
// models/contact.js - Contact model
module.exports = (sequelize, DataTypes) => {
const Contact = sequelize.define('Contact', {
name: DataTypes.STRING,
email: DataTypes.STRING,
position: DataTypes.STRING
}, {})
Contact.associate = function ({Vendor, VendorLocation}) {
Contact.belongsToMany(Vendor, { through: 'VendorContacts'})
Contact.belongsToMany(VendorLocation, { through: 'VendorLocationContacts'})
}
return Contact
} The result is:
If I log the relation in VendorContacts: {
name: 'VendorContacts',
description: undefined,
type: undefined,
args: [],
resolve: undefined,
subscribe: undefined,
deprecationReason: undefined,
extensions: [Object: null prototype] {},
astNode: undefined
} |
Thank you, I will replicate this issue and get back with a solution. |
Thank you so much, @alirizwan! |
Hi @alirizwan. I know your time is valuable, and that this is an open-source project. If you have time, I wonder if you might point me in the right direction(s) so I can troubleshoot this myself? Thanks.. |
Hi Ben, indeed I can help you and I am working this weekend on this. You can join this discord: https://discord.gg/jcFeJCR8
Join the graphcraft Discord Server!<https://discord.gg/jcFeJCR8>
Check out the graphcraft community on Discord - hang out with 1 other members and enjoy free voice and text chat.
discord.gg
…________________________________
From: Ben Weller ***@***.***>
Sent: Thursday, February 1, 2024 10:39 PM
To: almost-full-stack/graphcraft ***@***.***>
Cc: Ali Rizwan ***@***.***>; Mention ***@***.***>
Subject: Re: [almost-full-stack/graphcraft] `belongsToMany` associations have undefined output type (Issue #92)
Hi @alirizwan<https://github.com/alirizwan>. I know your time is valuable, and that this is an open-source project. If you have time, I wonder if you might point me in the right direction(s) so I can troubleshoot this myself? Thanks..
—
Reply to this email directly, view it on GitHub<#92 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADAUKBR7PA7ZUX7UGPW74JTYRQDPNAVCNFSM6AAAAABCLDMTACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRSGI4TCOBSGE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
You can fix it by creating your through models to be sequelize models instead of String, in the meantime I will fix the bug. |
Awesome. Thank you.Sent from my iPhoneOn Feb 4, 2024, at 12:53, Ali Rizwan ***@***.***> wrote:
You can fix it by creating your through models to be sequelize models instead of String, in the meantime I will fix the bug.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
For example your
Just an empty sequelize model and then in through you can do |
@tapvt I have found the issue, it was a tricky one. It will be fixed in next version. |
I've run into an issue regarding
belongsToMany
relationships. It seems that a type is not generated when there is a join table. This is causinggraphcraft
to not function usinggraphql
andgraphql-http
(specifically the express library).For example:
This is the error:
The type of Workorder.WorkorderParts must be Output Type but got: undefined.
We have a
Workorder
model, aParts
model and a join table,WorkorderParts
.Can anyone provide any guidance as to why this is happening? Is this a known issue or am I just doing something incorrectly?
Thanks in advance.
The text was updated successfully, but these errors were encountered: