Apollo-server-adonis-directive-pack
  • Introduction
  • Usage
  • API
    • Query
      • @all
      • @find
    • Mutation
      • @create
      • @createMany
      • @update
      • @delete
    • Relationship
      • @hasOne
      • @hasMany
      • @belongsTo
Powered by GitBook
On this page
  • For a separate add use
  • Definition
  • Example

Was this helpful?

  1. API
  2. Relationship

@hasMany

One to many relationship

For a separate add use

/* ... */
const {
  HasManyDirective,
  HasManyTypeDefs
} = require('apollo-server-adonis-directives-pack/src/directives/relationship/HasMany')

makeExecutableSchema({ 
  /* ... */ 
  typeDefs: [ HasManyTypeDefs, /* ... */ ],
  schemaDirectives: { HasManyDirective, /* ... */} 
})

Definition

HasManyTypeDefs
directive @hasMany(
  # By default, the model will be calculated from the name
  # of the returned "type" with the prefix 'App/Model/'
  model: String,
  # By default, the column will be calculated from the name 
  # of the "type" with the postfix '_id'
  ownerColumn: String,
  # By default localColumn = 'id'
  localColumn:String) on FIELD_DEFINITION

Example

type User {
    id: ID!
    name: String
    posts: [Post] @hasMany #ownerColumn: user_id
}

type Post {
    id: ID!
    title: String!
    text: String
    user_id: Int!
}

This directive uses a DataLoader but does not cache the results.

Previous@hasOneNext@belongsTo

Last updated 4 years ago

Was this helpful?