2017-04-22 5 views
2

を解決し、私は次のクエリと一緒にexpress-graphqlを使用しています:GraphQLはGraphQLObjectType

invitations { 
    sent 
    received 
} 

次のように(簡体字)、スキーマ定義は次のとおりです。

resolveメソッドが sentために呼び出されることはありませんが
const InvitationType = new GraphQLObjectType({ 
    name: 'InvitationType', 
    description: 'Friends invitations', 
    fields: { 
     sent: { 
      type: new GraphQLList(GraphQLString), 
      description: 'Invitations sent to friends.', 
      resolve() { 
      return ['sentA']; 
      } 
     }, 
     received: { 
      type: new GraphQLList(GraphQLString), 
      description: 'Invitations received from friends.', 
      resolve() { 
      return ['receivedA', 'receivedB']; 
      } 
     } 
    } 
}); 

// Root schema 
const schema = new GraphQLSchema({ 
    query: new GraphQLObjectType({ 
     name: 'RootQueryType', 
     fields: { 
      invitations: { 
       type: InvitationType // no resolve() method here. 
      } 
     } 
    }) 
}); 

フィールドはreceivedです。戻って上記のクエリ:

{data: {invitations: {sent: null, received: null}}} 

親(invitations)フィールド上のresolve()メソッドを定義することなく、ネストされたフィールド(sentreceived)を解決する方法はありますか?

答えて

0

これは私のために働いた! GraphQL Documentationによると、resolveメソッドが非スカラーを返す場合、実行は続行されます。したがって、次のコードが動作します:

// Root schema 
const schema = new GraphQLSchema({ 
    query: new GraphQLObjectType({ 
     name: 'RootQueryType', 
     fields: { 
     invitations: { 
      type: InvitationType, 
      resolve:() => ({}) // Resolve returns an object. 
     } 
     } 
    }) 
}); 

希望します。乾杯!

関連する問題