entria / entria-graphql

GraphQL Generators for Entria Projects
MIT License
19 stars 1 forks source link

it is using field name instead of ref on graphql type and loader #39

Closed sibelius closed 6 years ago

sibelius commented 6 years ago

failing model

import mongoose from 'mongoose';

const { ObjectId } = mongoose.Schema.Types;

const Schema = new mongoose.Schema({
  name: {
    type: String,
    maxlength: 250,
    description: 'Product Group Name',
  },
  description: {
    type: String,
    required: false,
    description: 'Product Group description (optional)',
  },
  author: {
    type: ObjectId,
    ref: 'User',
    description: 'User that created this product product',
  },
  mainProduct: {
    type: ObjectId,
    ref: 'Product',
    description: 'Main Product',
  },
  active: {
    type: Boolean,
    default: true,
    indexed: true,
    description: 'If this ProductGroup is active or not',
  },
}, {
  timestamps: {
    createdAt: 'createdAt',
    updatedAt: 'updatedAt',
  },
  collection: 'product_group',
});

export default mongoose.model('ProductGroup', Schema);
export default new GraphQLObjectType(
  ({
    name: 'ProductGroup',
    description: 'Represents ProductGroup',
    fields: () => ({
      id: globalIdField('ProductGroup'),
      name: {
        type: GraphQLString,
        description: 'Product Group Name',
        resolve: obj => obj.name,
      },
      description: {
        type: GraphQLString,
        description: 'Product Group description (optional)',
        resolve: obj => obj.description,
      },
      author: {
        type: AuthorType,
        description: 'User that created this product product',
        resolve: async (obj, args, context) => await AuthorLoader.load(context, obj.author),
      },
      mainProduct: {
        type: MainProductType,
        description: 'Main Product',
        resolve: async (obj, args, context) => await MainProductLoader.load(context, obj.mainProduct),
      },

author should be UserType not AuthorType