Closed pklotz-jdisc closed 3 years ago
Hi Peter I’m not sure I understand your question. If you take those examples you would substitute my query (defined in the $introspectionQuery variable for the first example) with your query. Variables in PowerShell aren’t necessarily hard-coded and the values could be dynamically derived. Could you give an example in another programming language of what you’re looking for?
Hi Peter, the example below demonstrates dynamically constructing queries based on parameter values contained within an array. I hope this helps.
# List of movies we're going to iterate through to generate queries:
$movieList = @("HOPE", "EMPIRE", "JEDI")
# Our GraphQL endpoint
$movieGqlEndpoint = "http://myapi/starwars/v1/graphql"
# Iterate through each episode in the array, construct a query and pass on to Invoke-GraphQLQuery:
foreach ($episode in $movieList) {
$movieQuery = "query HeroNameAndFriends($episode`: Episode) {
hero(episode: $episode) {
name
friends {
name
}
}
}"
Invoke-GraphQLQuery -Query $movieQuery -Uri $movieGqlEndpoint -Raw
}
Ah thanks, that was, what I was looking for Normally when I use a graphql APIs it allows me to specify the parameter separately as parameters to the Invoke-GraphQLQuery function but you simply evaluate them in the string context. Security-wise that is of course string evaluation but that's fine for the moment.
So I would simply use the Powershell variables $user and $password in the string " mutation($user: String, $password: String) { authentication { login(login: $user, password: $password) { status accessToken refreshToken rights } } }"
Added the ability to take GraphQL query variables via the -Variables parameter in version 1.1.3.
Hi,
I do not understand from the documentation how to pass a parameter to a query or a mutation? In the examples hard-coded values are used instead of the graphql parameter mechanism. Could you make an additional example please?
Thanks, Peter