2016-09-25 15 views
4

私はGraphQLを初めて使用しています。いつも、私はエラーメッセージ "タイプユーザーのフィールド投稿に不明な引数ID"を持っています。私はいくつかの特定の投稿だけを持っていきたいと思っています。ここGraphqlフィールドの不明な引数

{ people(id:[1,2]) { 
      id 
      username 
      posts(id:2) { 
       title 
       tags { 
       name 
       } 
      } 
      } 
     } 

は私Schema.jsファイルです..あなたはそれゆえ、ユーザーの引数が欠落しているよう

var graphql = require('graphql'); 
var Db = require('./db'); 
var users = new graphql.GraphQLObjectType({ 
    name : 'user', 
    description : 'this is user info', 
    fields : function(){ 
    return { 
     id :{ 
     type : graphql.GraphQLInt, 
     resolve(user){ 
      return user.id; 
     } 
     }, 
     username :{ 
     type : graphql.GraphQLString, 
     resolve(user){ 
      return user.username; 
     } 
     }, 

     posts:{ 
     id:{ 
      type : graphql.GraphQLString, 
      resolve(post){ 
      return post.id; 
      } 
     }, 
     type: new graphql.GraphQLList(posts), 
     resolve(user){ 
      return user.getPosts(); 
     } 
     } 


    } 
    } 
}); 



var posts = new graphql.GraphQLObjectType({ 
    name : 'Posts', 
    description : 'this is post info', 
    fields : function(){ 
    return { 
     id :{ 
     type : graphql.GraphQLInt, 
     resolve(post){ 
      return post.id; 
     } 
     }, 
     title :{ 
     type : graphql.GraphQLString, 
     resolve(post){ 
      return post.title; 
     } 
     }, 
     content:{ 
     type : graphql.GraphQLString, 
     resolve(post){ 
      return post.content; 
     } 
     }, 
     person :{ 
     type: users, 
     resolve(post){ 
      return post.getUser(); 
     } 
     }, 

     tags :{ 
     type: new graphql.GraphQLList(tags), 
     resolve(post){ 
      return post.getTags(); 
     } 
     } 
    } 
    } 
}); 

var tags = new graphql.GraphQLObjectType({ 
    name : 'Tags', 
    description : 'this is Tags info', 
    fields : function(){ 
    return { 
     id :{ 
     type : graphql.GraphQLInt, 
     resolve(tag){ 
      return tag.id; 
     } 
     }, 
     name:{ 
     type : graphql.GraphQLString, 
     resolve(tag){ 
      return tag.name; 
     } 
     }, 
     posts :{ 
     type: new graphql.GraphQLList(posts), 
     resolve(tag){ 
      return tag.getPosts(); 
     } 
     } 
    } 
    } 
}); 

var query = new graphql.GraphQLObjectType({ 
    name : 'query', 
    description : 'Root query', 
    fields : function(){ 
    return { 
    people :{ 
     type : new graphql.GraphQLList(users), 
     args :{ 
      id:{type: new graphql.GraphQLList(graphql.GraphQLInt)}, 
      username:{ 
      type: graphql.GraphQLString 
      } 
     }, 
     resolve(root,args){ 
      return Db.models.user.findAll({where:args}); 
     } 
     }, 

     posts:{ 
     type : new graphql.GraphQLList(posts), 
     args :{ 
      id:{ 
      type: graphql.GraphQLInt 
      }, 
      title:{ 
      type: graphql.GraphQLString 
      }, 
     }, 
     resolve(root,args){ 
      return Db.models.post.findAll({where:args}); 
     } 
     }, 

     tags :{ 
     type : new graphql.GraphQLList(tags), 
     args :{ 
      id:{ 
      type: graphql.GraphQLInt 
      }, 
      name:{ 
      type: graphql.GraphQLString 
      }, 
     }, 
     resolve(root,args){ 
      return Db.models.tag.findAll({where:args}); 
     } 
     } 

    } 
    } 

}); 
var Schama = new graphql.GraphQLSchema({ 
    query : query, 
    mutation : Mutation 
}) 

module.exports = Schama; 
+0

のように見える?ほとんどの場合、スキーマ内でid引数を正しく宣言していない可能性があります。 – helfer

+0

schema.jsファイルを追加しました。一度チェックしてください。@helfer –

答えて

5

に見える、それは次のようになります。自分のスキーマを何

var users = new graphql.GraphQLObjectType({ 
    name : 'user', 
    description : 'this is user info', 
    fields : function(){ 
    return { 
     id :{ 
     type : graphql.GraphQLInt, 
     resolve(user){ 
      return user.id; 
     } 
     }, 
     username :{ 
     type : graphql.GraphQLString, 
     resolve(user){ 
      return user.username; 
     } 
     }, 

     posts:{ 
     args: { 
     id:{ 
      type : graphql.GraphQLInt, 
     }, 
     type: new graphql.GraphQLList(posts), 
     resolve(user, args){ 
      // Code here to use args.id 
      return user.getPosts(); 
     } 
     } 


    } 
    } 
}); 
+0

ありがとう@HagaiCo –

関連する問題