0

I can not get the following to work in PowerShell script, how would you break down the following?

jq -n --arg schema "$(cat schema.graphql)" '{ query: "mutation addSchema($sch: String!) { addSchema(input: { schema: $sch }) { schema { schema } } }", variables: { sch: $schema }}' | curl -X POST -H "Content-Type: application/json" http://localhost:5500/admin -d @- | jq -r

I have the following:

function Add-this(){
Param
(
    [Parameter(Mandatory=$true)]
    [string]$Target,
    [Parameter(Mandatory=$true)]
    [string]$FileName
)

$Body = jq -n --arg schema "$(cat $FileName)" '{ query: "mutation addSchema($sch: String!) { addSchema(input: { schema: $sch }) { schema { schema } } }", variables: { sch: $schema }}'

Invoke-RestMethod -Headers $headers -Method Post -Uri "http://$Target:5500/admin" -Body ...

}

Chris G.
  • 23,930
  • 48
  • 177
  • 302
  • 1
    As [noted before](https://stackoverflow.com/a/59036879/45375) - sadly - you must `\ `-escape `"` instances embedded in strings. Also - and this may just be due to not showing all code - your expandable string references variables that are neither passed as parameters nor defined inside your function; similarly, `$headers` is not defined. – mklement0 Nov 29 '19 at 03:46
  • 1
    Additionally, `"$(cat $FileName)"` doesn't work the same way that it does in Bash - you'll end up with the file's lines joined with spaces. Instead, use `(Get-Content -Raw $FileName)`. – mklement0 Nov 29 '19 at 03:56

0 Answers0