2017-12-11 10 views
0

GraphQLの新機能で、GraphiQLを使用してクエリを送信する際に問題が発生しています。GraphQL、GraphiQLを使用したクエリの構文が正しくありません

は、これは私のschema.js

const graphql = require('graphql'); 
const _ = require('lodash'); 
const{ 
    GraphQLObjectType, 
    GraphQLInt, 
    GraphQLString, 
    GraphQLSchema 
} = graphql; 

const users = [ 
    {id:'23', firstName:'Bill', age:20}, 
    {id:'47', firstName:'Samantha', age:21} 
]; 

const UserType = new GraphQLObjectType({ 
    name: 'User', 
    fields:{ 
     id: {type: GraphQLString}, 
     firstName: {type: GraphQLString}, 
     age:{type: GraphQLInt} 
    } 
}); 

const RootQuery = new GraphQLObjectType({ 
    name: 'RootQueryType', 
    fields:{ 
     user: { 
      type: UserType, 
      args:{ 
       id: {type: GraphQLString} 
      }, 
      resolve(parentValue, args){ // move the resolve function to here 
       return _.find(users, {id: args.id}); 
      } 
     }, 

    } 
}); 

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

と私は思いgraphiqlで次のクエリを実行すると:私は「得た構文エラーGraphQL要求

query { 
    user { 
    id: "23" 
    } 
} 

(3:9)期待の名前を見つけました文字列 "が、私はID" 23 "のユーザーを取得することを期待します。

私には何が欠けていますか?

答えて

2

あなたはそれではなく、チュートリアルの引数セクションをご覧ください

query { 
    user(id: “23”) { 
    id 
    firstName 
    age 
    } 
} 

のようになりますあなたの選択にあなたの引数の値を入れているhttp://graphql.org/graphql-js/passing-arguments/

関連する問題