@belongsTo
Belongs to (one or more)
For a separate add use
/* ... */
const {
BelongsToDirective,
BelongsToTypeDefs
} = require('apollo-server-adonis-directives-pack/src/directives/relationship/BelongsTo')
makeExecutableSchema({
/* ... */
typeDefs: [ BelongsToTypeDefs, /* ... */ ],
schemaDirectives: { BelongsToDirective, /* ... */}
})
Definition
BelongsToTypeDefs
directive @belongsTo(
# By default, the model will be calculated from the name
# of the returned "type" with the prefix 'App/Model/'
model: String,
# By default ownerColumn = 'id'
ownerColumn: String,
# By default, the column will be calculated from the name
# of the returned "type" with the postfix '_id'
localColumn:String) on FIELD_DEFINITION
Example
type User {
id: ID!
name: String
country_id: Int!
}
type Post {
id: ID!
title: String!
text: String
user_id: Int!
user: User @belongsTo #localColumn: user_id
}
type Country {
id: ID!
name: String
users: [User] @belondsTo(localColumn: "id", ownerColumn: "country_id")
}
Last updated
Was this helpful?