Vincit / objection-graphql

GraphQL schema generator for objection.js
MIT License
307 stars 35 forks source link

Error: relation type "HasManyRelation" is not supported #78

Open ryanvanderpol opened 5 years ago

ryanvanderpol commented 5 years ago

I have two models (Order and OrderItems) where Order has relationMappings defined as follows:

    static get relationMappings(){

        const OrderItem = require('./OrderItem');

        return {
            items: {
                relation: Model.HasManyRelation,
                modelClass: OrderItem,
                join: {
                    from: 'orders.id',
                    to: 'order_items.order_id'
                }
            }
        }
    }

When I use the GraphQL Builder, as follows:

const schema = builder()
  .model(Order, { fieldName: 'order', listFieldName: 'orders' })
  .model(OrderItem)
  .build();

I get the following error:

Error: relation type "HasManyRelation" is not supported
    at SchemaBuilder._relationField (/.../node_modules/objection-graphql/lib/SchemaBuilder.js:243:11)

Looking at the code in the _relationField method it seems that HasManyRelation should be supported.

Not 100% sure why this is happening, but it might be related to the fact that I have all my models defined in a separate NPM package so the instanceof objection.HasManyRelation check isn't referring to the same instance of objection that the models were built with?