问题描述
只是基本的阿波罗查询请求
this.client.query({ query: gql` { User(okta: $okta){ id } }` }).then(result => { this.setState({userid: result.data.User}); console.log(this.state.userid.id) }).catch(error => { this.setState({error: <Alert color="danger">Error</Alert>}); });
问题是,如何/在哪里设置$ OKTA变量.
在Stackoverflow或Google上找不到解决方案 - 如果有人可以帮助我,那就很棒:)
推荐答案
应该是这样的:
const query = gql` query User($okta: String) { User(okta: $okta){ id } } `; client.query({ query: query, variables: { okta: 'some string' } })
可以在此处找到带有所有详细信息的Apollo客户端的文档: https://www.apollographql.com/docs/react/api/apollo-client.html#apolloclient.query.query
问题描述
Just a basic apollo query request
this.client.query({ query: gql` { User(okta: $okta){ id } }` }).then(result => { this.setState({userid: result.data.User}); console.log(this.state.userid.id) }).catch(error => { this.setState({error: <Alert color="danger">Error</Alert>}); });
The question is, how/where to set the $okta variable.
Didn't find a solution on Stackoverflow or Google - would be great if someone could help me:)
推荐答案
It should be something like this:
const query = gql` query User($okta: String) { User(okta: $okta){ id } } `; client.query({ query: query, variables: { okta: 'some string' } })
The documentation for Apollo client with all the details can be found here: https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClient.query