2017-12-26 19 views
0

私はnode、express、mongoose、およびgraphqlを使用しています。GraphQL Schema.jsファイルエラー - Node/express

私はgraphqlコンソールでこのエラーが発生しています: "message": "The type of SocialPostInQue.socialPost must be Output Type but got: undefined.\n\nThe type of SocialPostInQue.schedule must be Output Type but got: undefined.\n\nThe type of Mutation.addSocialPostInQue(socialPost:) must be Input Type but got: undefined.\n\nThe type of Mutation.addSocialPostInQue(schedule:) must be Input Type but got: undefined."エラーは私がSchema.jsファイルのタイプで作成していると思います。

質問または突然変異を実行していないため、undefinedがどこから来ているのか分かりません。私のコードに何か問題はありますか?

マイSocialPostInQueスキーマファイルは次のとおりです。

const mongoose = require('mongoose'); 
const Schema = mongoose.Schema; 

const SocialPostInQueSchema = new Schema({ 
    userId: String, 
    socialPost: { 
     id: String, 
     message: String, 
     image: { 
      url: String 
     } 
    }, 
    schedule: { 
     month: String, 
     date: Number, 
     hour: String, 
     minute: String 
    } 
}); 

module.exports = mongoose.model('SocialPostInQue', SocialPostInQueSchema); 

そして、私のSchema.jsファイルは次のとおりです。

const axios = require('axios'); 
const mongoose = require('mongoose'); 
const Schema = mongoose.Schema; 
const { 
    GraphQLObjectType, 
    GraphQLString, 
    GraphQLInt, 
    GraphQLID, 
    GraphQLSchema, 
    GraphQLList, 
    GraphQLNonNull 
} = require('graphql'); 

/****** Mongoose Schemas ******/ 
const SOCIALPOSTINQUE = require('./socialPostInQue'); 

/******* Types POSSIBLE ORIGIN*******/ 
const SocialPostInQueType = new GraphQLObjectType({ 
    name:'SocialPostInQue', 
    fields:() => ({ 
     id: {type:GraphQLID}, 
     userId: {type:GraphQLID}, 
     socialPost: { 
      id: {type:GraphQLID}, 
      message: {type:GraphQLString}, 
      image: { 
       url: {type:GraphQLString} 
      } 
     }, 
     schedule: { 
      month: {type:GraphQLString}, 
      date: {type:GraphQLInt}, 
      hour: {type:GraphQLString}, 
      minute: {type:GraphQLString} 
     } 
    }) 
}); 

/****** functions ******/ 
const socialPostInQueList =() => { 
    return new Promise((resolve, reject) => { 
     SOCIALPOSTINQUE.find((err, socialPostsInQue) => { 
      if (err) reject(err) 
      else resolve(socialPostsInQue) 
     }) 
    }) 
}; 

/****** Root Query WHERE 'SocialPostInQue.socialPost OUTPUT UNDEFINED ERROR IS******/ 
const RootQuery = new GraphQLObjectType({ 
    name: 'RootQueryType', 
    fields: { 
     socialPostInQue: { 
      type: SocialPostInQueType, 
      args: { 
       id: {type:GraphQLID} 
      }, 
      resolve (parentValue, {id}) { 
       return SOCIALPOSTINQUE.findById(id) 
      } 
     }, 
     socialPostsInQue:{ 
      type: new GraphQLList (SocialPostInQueType), 
      resolve (parentValue, args) { 
       return socialPostInQueList() 
      } 
     } 
    } 
}) 

/***** Root Mutations WHERE 'Mutation.addSocialPostInQue...' ERRORS COME FROM*******/ 
const mutation = new GraphQLObjectType({ 
    name:'Mutation', 
    fields:{ 
     addSocialPostInQue:{ 
      type: SocialPostInQueType, 
      args:{ 
       userId: {type: new GraphQLNonNull (GraphQLID)}, 
       socialPost: { 
        id: {type: new GraphQLNonNull (GraphQLID)}, 
        message: {type: new GraphQLNonNull (GraphQLString)}, 
        image: { 
         url: {type: new GraphQLNonNull (GraphQLString)} 
        } 
       }, 
       schedule: { 
        month: {type: new GraphQLNonNull (GraphQLString)}, 
        date: {type: new GraphQLNonNull (GraphQLInt)}, 
        hour: {type: new GraphQLNonNull (GraphQLString)}, 
        minute: {type: new GraphQLNonNull (GraphQLString)} 
       } 
      }, 
      resolve(parentValue, args){ 
       console.log('READ', args) 
       let newSocialPostInQue = new SOCIALPOSTINQUE({ 
        name: args.name, 
        email: args.email, 
        age: args.age, 
        userId: args.userId, 
        socialPost: { 
         id: args.socialPost.id, 
         message: args.socialPost.message, 
         image: { 
          url: args.socialPost.image.url 
         } 
        }, 
        schedule: { 
         month: args.schedule.month, 
         date: args.schedule.date, 
         hour: args.schedule.hour, 
         minute: args.schedule.minute 
        } 
       }); 
       return new Promise((resolve, reject) => { 
        newSocialPostInQue.save(function (err) { 
         if(err) reject(err) 
         else resolve(newSocialPostInQue) 
        }) 
        console.log ("New Social Post In Que Added") 
       }); 
      } 
     } 
    } 
}) 

module.exports = new GraphQLSchema({ 
    query: RootQuery, 
    mutation 
}); 

答えて

0

すべてのネストされた非スカラー型は、オブジェクト型として構成する必要があります。 socialPostimagescheduleフィールドに注意してください。

const SocialPostInQueType = new GraphQLObjectType({ 
    name:'SocialPostInQue', 
    fields:() => ({ 
     id: {type:GraphQLID}, 
     userId: {type:GraphQLID}, 
     socialPost: new GraphQLObjectType({ 
      name: 'SocialPostType', 
      fields: { 
       id: {type:GraphQLID}, 
       message: {type:GraphQLString}, 
       image: new GraphQLObjectType({ 
        name: 'ImageType', 
        fields: { 
         url: {type:GraphQLString} 
        } 
       }) 
      } 
     }), 
     schedule: new GraphQLObjectType({ 
      name: 'SocialPostSchedule', 
      fields: { 
       month: {type:GraphQLString}, 
       date: {type:GraphQLInt}, 
       hour: {type:GraphQLString}, 
       minute: {type:GraphQLString} 
      } 
     }) 
    }) 
})