diepm / vim-rest-console

A REST console for Vim.
658 stars 54 forks source link

Variable replace not working #83

Open camilacremoneze opened 4 years ago

camilacremoneze commented 4 years ago

I have tried to run some rest graphql like this:

Graphql

http://

user = "2dc6beda-816f-11e9-be55-db9c03003941"

Accept: / Content-Type: application/graphql authorization: *****

POST /api/graphql mutation { Accept (ownerId: :user ){ ownerId }
}

It did not replace variable into requisition.

diepm commented 4 years ago

I've noticed two things. First is that you don't need to quote the value as "2dc6..." unless you mean to include the quotes in the value. Second is that you seem to use :rest as the placeholder but your variable is user.

camilacremoneze commented 4 years ago

Sorry, I have just replace "rest" to "user", cause it was just an wrong transcript... I have tried without quotes, also with quotes, and also I have tried change order of variable; latter I will log the complete error.

camilacremoneze commented 4 years ago

curl: (52) Empty reply from server

-Type: application/graphql' -H 'user = 2dc6beda-816f-11e9-be55-db9c03003941' -H 'authorization: *******' -X POST --data 'mutation { Accept (ownerId: :user){ ownerId }}' 'http://<some_url>/api/graphql'

diepm commented 4 years ago

It seems that the server doesn't respond as curl: (52) return code. One way to debug is to set vrc_show_command (:let g:vrc_show_command=1) to get the curl command when run and manually run it from console.

diepm commented 4 years ago

Oh actually I notice that :user is not substituted. It should be placed in the global scope. Could you double check with https://github.com/diepm/vim-rest-console#53-global-variable-declaration

In you case, I guess it can be like

# Global scope
user = abcd-1234
--
# End global scope

http://some-url
some: headers
POST /some-where
mutation { ... ownerId: :user }
camilacremoneze commented 4 years ago

Ohh tks! I must follow pattern Global scope above... (Doc could be a bit more explicit, that syntax above is required.)

Now my variable is being replaced into request, but it also includes -H -user=2dc6beda-816f-11e9-be55-db9c03003941' and this brokes my request.

curl -H 'Accept: */*' -H 'Content-Type: application/graphql' -H 'authorization: ********' -H 'user = 2dc6beda-816f-11e9-be55-db9c03003941' -X POST --data 'mutation { Accept (ownerId: 2dc6beda-816f-11e9-be55-db9c03003941){ ownerId }}' '<some_url>/api/graphql

Response: curl: (3) URL using bad/illegal format or missing URL

# Global scope.
user = 2dc6beda-816f-11e9-be55-db9c03003941
--
# End global scope.

http://<some_url>

Accept: */*
Content-Type: application/graphql
authorization: ******

POST /api/graphql
mutation {
    Accept (ownerId: :user){
        ownerId
    }
}
diepm commented 4 years ago

You still have -H 'user = 2dc6beda-816f-11e9-be55-db9c03003941' in your command. It seems you still have this variable defined in the local block. Could you double check?

It's the command when I try the snippet above.

curl -sS -H 'Accept: */*' -H 'Content-Type: application/graphql' -H 'authorization: ******' -X POST --data 'mutation { Accept (ownerId: 2dc6beda-816f-11e9-be55-db9c03003941){ ownerId }}' 'http://<some_url>/api/graphql'