Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from: 'Person.pid',
to: 'Person.id'
}
},
pets: {
relation: objection.HasManyRelation,
modelClass: Animal,
join: {
from: 'Person.id',
to: 'Animal.ownerId'
}
},
movies: {
relation: objection.ManyToManyRelation,
modelClass: Movie,
join: {
from: 'Person.id',
through: {
from: 'Person_Movie.actorId',
to: 'Person_Movie.movieId'
},
to: 'Movie.id'
}
}
};
Animal.relationMappings = {
owner: {
relation: objection.BelongsToOneRelation,
modelClass: Person,
from: 'Person.id',
to: 'Person.pid'
}
},
pets: {
relation: objection.HasManyRelation,
modelClass: Animal,
join: {
from: 'Person.id',
to: 'Animal.ownerId'
}
},
movies: {
relation: objection.ManyToManyRelation,
modelClass: Movie,
join: {
from: 'Person.id',
through: {
from: 'Person_Movie.actorId',
to: 'Person_Movie.movieId'
},
to: 'Movie.id'
}
}
};
return {
Person: Person,
Animal: Animal,
Movie: Movie
from: 'Person.pid',
to: 'Person.id'
}
},
pets: {
relation: objection.HasManyRelation,
modelClass: Animal,
join: {
from: 'Person.id',
to: 'Animal.ownerId'
}
},
movies: {
relation: objection.ManyToManyRelation,
modelClass: Movie,
join: {
from: 'Person.id',
through: {
from: 'Person_Movie.actorId',
to: 'Person_Movie.movieId'
},
to: 'Movie.id'
}
}
};
}
}
_relationField(modelData, relation) {
if (relation instanceof objection.HasOneRelation
|| relation instanceof objection.BelongsToOneRelation
|| relation instanceof objection.HasOneThroughRelation) {
return {
type: this._typeForModel(modelData),
args: _.omit(modelData.args, OMIT_FROM_RELATION_ARGS),
};
} else if (relation instanceof objection.HasManyRelation || relation instanceof objection.ManyToManyRelation) {
return {
type: new GraphQLList(this._typeForModel(modelData)),
args: _.omit(modelData.args, OMIT_FROM_RELATION_ARGS),
};
}
throw new Error(`relation type "${relation.constructor.name}" is not supported`);
}