援引阿波罗GraphQL客户端的查询
问题描述:
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应用程序。任何人都知道如何在事件中使用参数调用查询,例如,当用户单击按钮时,我想用参数触发查询。
答
要调用查询中的事件,而不是作为一个高阶组件,您应该:
进口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Ø