Python 如何在GraphQL中返回函数结果
我在前端使用React、Apollo和GraphQL,在后端使用Django、Python和Graphene 我想实现搜索栏,当用户点击搜索按钮时,我想用用户输入执行GraphQL查询 在后端,我想对该字符串进行绘图,并将其传递给函数,然后将函数返回的结果传递回前端 我的代码如下: 前端Python 如何在GraphQL中返回函数结果,python,django,reactjs,graphql,graphene-python,Python,Django,Reactjs,Graphql,Graphene Python,我在前端使用React、Apollo和GraphQL,在后端使用Django、Python和Graphene 我想实现搜索栏,当用户点击搜索按钮时,我想用用户输入执行GraphQL查询 在后端,我想对该字符串进行绘图,并将其传递给函数,然后将函数返回的结果传递回前端 我的代码如下: 前端 export const GET_RESULTS = gql` query SearchVinResults($vin: String!){ searchVinResults(vin: $vin) {
export const GET_RESULTS = gql`
query SearchVinResults($vin: String!){
searchVinResults(vin: $vin) {
id
label
url
}
}`;
class VinSearch extends Component {
onVinSearch(e) {
e.preventDefault();
const {value, client: {query}} = this.props;
query({query: GET_RESULTS, variables: { vin: value }});
}
render() {
const {value, clearSearch, onChange} = this.props;
return (
<SearchField
onChange={e => onChange(e)}
clearSearch={() => clearSearch()}
value={value}
clearIcon="fal fa-times"
placeholder="Search VIN"
withButton={true}
buttonStyles={{borderLeftWidth: 0}}
onClick={e => this.onVinSearch(e)}
/>
);
}
}
export default withApollo(VinSearch);
有什么想法吗
def resolve_search_vin_results(self, info, **kwargs):
# Here I want to do something like
vin = info['vin']
results = get_vins(vin)
return results