Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripts): add request.body.getComputed() #262

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

gorillamoe
Copy link
Member

Returns the string request body as sent via curl; with variables substituted, or undefined if there is no body.

Very useful if you want to see the request body as it was sent to the server.

The tryGetSubstituted method will substitute variables with their values, but leave the rest of the body as is.

If you have a GraphQL query in the body, for example, the getComputed method will show the query as it was sent to the server, which is quite different from the substituted version.

As an example, if you have a request body like this:

query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "{{ENV_VAR_CLIENT_NAME}}"
  }
}

Then the getComputed method will
return the body as it was sent to the server:

{"query": "query getRestClient($name: String!) { restclient(name: $name) { id name editorsSupported { name } } } ", "variables": {"variables": {"name": "kulala"}}}

whereas the tryGetSubstituted method will
return the body with variables substituted as seen in your script:

query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "kulala"
  }
}

The getComputed method is always undefined for binary bodies.

@gorillamoe gorillamoe added the enhancement New feature or request label Oct 6, 2024
@gorillamoe gorillamoe self-assigned this Oct 6, 2024
@gorillamoe gorillamoe requested a review from Grueslayer as a code owner October 6, 2024 11:34
Returns the `string` request body as sent via curl; with variables substituted,
or `undefined` if there is no body.

Very useful if you want to see the request body as it was sent to the server.

The `tryGetSubstituted` method will substitute variables with their values,
but leave the rest of the body as is.

If you have a GraphQL query in the body, for example, the `getComputed`
method will show the query as it was sent to the server,
which is quite different from the substituted version.

As an example, if you have a request body like this:

```graphql
query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "{{ENV_VAR_CLIENT_NAME}}"
  }
}
```

Then the `getComputed` method will
return the body as it was sent to the server:

```json
{"query": "query getRestClient($name: String!) { restclient(name: $name) { id name editorsSupported { name } } } ", "variables": {"variables": {"name": "kulala"}}}
```

whereas the `tryGetSubstituted` method will
return the body with variables substituted as seen in your script:

```graphql
query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "kulala"
  }
}
```

The `getComputed` method is always `undefined` for binary bodies.
@gorillamoe gorillamoe force-pushed the feat/scripts-get-computed-body branch from 401086d to 08ce122 Compare October 6, 2024 11:35
@gorillamoe gorillamoe merged commit 3407b68 into main Oct 6, 2024
3 checks passed
@gorillamoe gorillamoe deleted the feat/scripts-get-computed-body branch October 6, 2024 11:37
@gorillamoe
Copy link
Member Author

X-Ref: #194

gorillamoe added a commit to rcasia/kulala.nvim that referenced this pull request Oct 7, 2024
Returns the `string` request body as sent via curl; with variables substituted,
or `undefined` if there is no body.

Very useful if you want to see the request body as it was sent to the server.

The `tryGetSubstituted` method will substitute variables with their values,
but leave the rest of the body as is.

If you have a GraphQL query in the body, for example, the `getComputed`
method will show the query as it was sent to the server,
which is quite different from the substituted version.

As an example, if you have a request body like this:

```graphql
query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "{{ENV_VAR_CLIENT_NAME}}"
  }
}
```

Then the `getComputed` method will
return the body as it was sent to the server:

```json
{"query": "query getRestClient($name: String!) { restclient(name: $name) { id name editorsSupported { name } } } ", "variables": {"variables": {"name": "kulala"}}}
```

whereas the `tryGetSubstituted` method will
return the body with variables substituted as seen in your script:

```graphql
query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "kulala"
  }
}
```

The `getComputed` method is always `undefined` for binary bodies.
iamxiaojianzheng pushed a commit to iamxiaojianzheng/kulala.nvim that referenced this pull request Oct 24, 2024
Returns the `string` request body as sent via curl; with variables substituted,
or `undefined` if there is no body.

Very useful if you want to see the request body as it was sent to the server.

The `tryGetSubstituted` method will substitute variables with their values,
but leave the rest of the body as is.

If you have a GraphQL query in the body, for example, the `getComputed`
method will show the query as it was sent to the server,
which is quite different from the substituted version.

As an example, if you have a request body like this:

```graphql
query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "{{ENV_VAR_CLIENT_NAME}}"
  }
}
```

Then the `getComputed` method will
return the body as it was sent to the server:

```json
{"query": "query getRestClient($name: String!) { restclient(name: $name) { id name editorsSupported { name } } } ", "variables": {"variables": {"name": "kulala"}}}
```

whereas the `tryGetSubstituted` method will
return the body with variables substituted as seen in your script:

```graphql
query getRestClient($name: String!) {
  restclient(name: $name) {
    id
    name
    editorsSupported {
      name
    }
  }
}

{
  "variables": {
    "name": "kulala"
  }
}
```

The `getComputed` method is always `undefined` for binary bodies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant