2017-09-01 57 views
4

query screenshot援引阿波羅GraphQL客戶端的查詢

const allTeamApplicants = gql` 
    query ($id: ID!) { 
    allApplicants(filter: { user: { id: $id } }) { 
     id 
     firstName 
     lastName 
     appliedPosition 
     applicationStage 
     isFormFilled 
     isContractSigned 
     email 
     phoneNumber 
} 

我用阿波羅客戶端GraphQL在陣營的Web應用程序。任何人都知道如何在事件中使用參數調用查詢,例如,當用戶單擊按鈕時,我想用參數觸發查詢。

回答

3

要調用查詢中的事件,而不是作爲一個高階組件,您應該:

進口withApollo特設

import { withApollo } from 'react-apollo'; 

包裹你的組件與withApollo

const component = withApollo(Component) 

在組件內部,您將收到一個名爲client的新道具,您可以將其作爲承諾使用,例如:

function eventHandler(idParam) { 
    client.query({ 
    query: gql` 
     query ($id: ID!) { 
     allApplicants(filter: { user: { id: $id } }) { 
      id 
      firstName 
      lastName 
      appliedPosition 
      applicationStage 
      isFormFilled 
      isContractSigned 
      email 
      phoneNumber 
     } 
     }`, 
     variables: { 
     // set the variables defined in the query, in this case: query($id: ID!) 
     id: idParam 
     } 
    } 
    }) 
    .then(...) 
    .catch(...) 
} 

更多的信息在這裏:http://dev.apollodata.com/react/api-graphql.html#withApollØ

相關問題