Skip to content

Commit

Permalink
Add operationName to ScriptContextData
Browse files Browse the repository at this point in the history
  • Loading branch information
Lovro authored and imolorhe committed Mar 21, 2024
1 parent f9f713e commit 81414d4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class PostRequestEditorComponent {
{
headers: [],
environment: {},
operationName: '',
query: '',
variables: '',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class PreRequestEditorComponent {
{
headers: [],
environment: {},
operationName: '',
query: '',
variables: '',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ScriptContextStorage {
export interface ScriptContextData {
headers: HeaderState;
variables: string;
operationName: string;
query: string;
environment: IDictionary;
requestScriptLogs?: LogLine[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ describe('PreRequestService', () => {
const result = await service.executeScript(script, {
environment: {},
headers: [],
operationName: '',
query: '',
variables: '',
});

expect(result).toEqual({
environment: {},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -75,6 +77,7 @@ describe('PreRequestService', () => {
const result = await service.executeScript(script, {
environment: {},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -84,6 +87,7 @@ describe('PreRequestService', () => {
first: true,
},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -102,6 +106,7 @@ describe('PreRequestService', () => {
const result = await service.executeScript(script, {
environment: {},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -112,6 +117,7 @@ describe('PreRequestService', () => {
encoded: 'Zmlyc3Q=',
},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -129,6 +135,7 @@ describe('PreRequestService', () => {
const result = await service.executeScript(script, {
environment: {},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -139,6 +146,7 @@ describe('PreRequestService', () => {
decoded: 'first',
},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -156,6 +164,7 @@ describe('PreRequestService', () => {
const result = await service.executeScript(script, {
environment: {},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand All @@ -166,6 +175,7 @@ describe('PreRequestService', () => {
sha: 'a7937b64b8caa58f03721bb6bacf5c78cb235febe0e70b1b84cd99541461a08e',
},
headers: [],
operationName: '',
query: '',
variables: '',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class QueryService {
}

const query = (preTransformedData?.query || state.query.query || '').trim();
const operationName = (state.query.selectedOperation || '').trim();
const headers = preTransformedData?.headers || state.headers;
const variables =
preTransformedData?.variables || state.variables.variables;
Expand All @@ -67,6 +68,7 @@ export class QueryService {
{
environment,
headers,
operationName,
query,
variables,
}
Expand Down Expand Up @@ -128,6 +130,7 @@ export class QueryService {
}

const query = (preTransformedData?.query || state.query.query || '').trim();
const operationName = (state.query.selectedOperation || '').trim();
const headers = preTransformedData?.headers || state.headers;
const variables =
preTransformedData?.variables || state.variables.variables;
Expand All @@ -141,6 +144,7 @@ export class QueryService {
{
environment,
headers,
operationName,
query,
variables,
requestType,
Expand Down
3 changes: 2 additions & 1 deletion packages/altair-docs/docs/features/prerequest-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ This contains data used to process your GraphQL request.

**`altair.data.query`** - The GraphQL query sent to the server.

**`altair.data.operationName`** - The GraphQL query operation name sent to the server.

**`altair.data.environment`** - The formatted environment object containing the serialized set of environment data before your request is sent.

### altair.helpers
Expand Down Expand Up @@ -117,7 +119,6 @@ altair.helpers.setEnvironment('token_env', token);
// You can use the environment variables in Altair after setting it by following this blog post: https://sirmuel.design/altair-becomes-environment-friendly-%EF%B8%8F-f9b4e9ef887c
```


### altair.response (Available in post request script)

This contains response from your GraphQL request. **Note: This is only available in post request scripts.**
Expand Down

0 comments on commit 81414d4

Please sign in to comment.