Skip to content

Commit

Permalink
Assume query can be undefined.
Browse files Browse the repository at this point in the history
Closes #1054.
Closes #1005.
  • Loading branch information
imolorhe committed Nov 10, 2019
1 parent 7eacd78 commit f070a56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/app/containers/window/window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class WindowComponent implements OnInit, OnDestroy {
}

this.apiUrl = data.query.url;
this.query = data.query.query;
this.query = data.query.query || '';
this.httpVerb = data.query.httpVerb;
this.showHeaderDialog = data.dialogs.showHeaderDialog;
this.showVariableDialog = data.dialogs.showVariableDialog;
Expand Down Expand Up @@ -208,7 +208,7 @@ export class WindowComponent implements OnInit, OnDestroy {
...plugin,
props: {
sdl: state.schema.sdl,
query: state.query.query,
query: state.query.query || '',
},
context: {
setQuery: query => this.zone.run(() => this.updateQuery(query)),
Expand Down
14 changes: 7 additions & 7 deletions src/app/effects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class QueryEffects {
return observableEmpty();
}

const query = response.data.query.query.trim();
const query = (response.data.query.query || '').trim();
if (!query) {
return observableEmpty();
}
Expand All @@ -82,7 +82,7 @@ export class QueryEffects {
switchMap((_returnedData) => {
const { response, transformedData } = _returnedData;

const query = response.data.query.query.trim();
const query = (response.data.query.query || '').trim();
let url = this.environmentService.hydrate(response.data.query.url);
let variables = this.environmentService.hydrate(response.data.variables.variables);
let headers = this.environmentService.hydrateHeaders(response.data.headers);
Expand Down Expand Up @@ -435,7 +435,7 @@ export class QueryEffects {
const { response, transformedData } = res;
let connectionParams = undefined;
let subscriptionUrl = this.environmentService.hydrate(response.data.query.subscriptionUrl);
let query = this.environmentService.hydrate(response.data.query.query);
let query = this.environmentService.hydrate(response.data.query.query || '');
let variables = this.environmentService.hydrate(response.data.variables.variables);
let variablesObj = undefined;
let selectedOperation = response.data.query.selectedOperation;
Expand All @@ -444,7 +444,7 @@ export class QueryEffects {
subscriptionUrl = this.environmentService.hydrate(response.data.query.subscriptionUrl, {
activeEnvironment: transformedData.environment
});
query = this.environmentService.hydrate(response.data.query.query, {
query = this.environmentService.hydrate(response.data.query.query || '', {
activeEnvironment: transformedData.environment
});
variables = this.environmentService.hydrate(response.data.variables.variables, {
Expand Down Expand Up @@ -584,7 +584,7 @@ export class QueryEffects {
return { data: state.windows[action.windowId], windowId: action.windowId, action, settings: state.settings };
}),
switchMap(res => {
this.gqlService.prettify(res.data.query.query, res.settings.tabSize).then(prettified => {
this.gqlService.prettify(res.data.query.query || '', res.settings.tabSize).then(prettified => {
if (prettified) {
return this.store.dispatch(new queryActions.SetQueryAction(prettified, res.windowId));
}
Expand Down Expand Up @@ -652,7 +652,7 @@ export class QueryEffects {
}),
switchMap(res => {
const url = this.environmentService.hydrate(res.data.query.url);
const query = this.environmentService.hydrate(res.data.query.query);
const query = this.environmentService.hydrate(res.data.query.query || '');
const variables = this.environmentService.hydrate(res.data.variables.variables);
try {
const curlCommand = generateCurl({
Expand Down Expand Up @@ -812,7 +812,7 @@ export class QueryEffects {
if (!response) {
return observableEmpty();
}
const query = response.data.query.query.trim();
const query = (response.data.query.query || '').trim();
/**
* pre request execution context is passed the current headers, environment, variables, query, etc
* and returns a set of the same that would have potentially been modified during the script execution.
Expand Down
9 changes: 5 additions & 4 deletions src/app/reducers/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export interface QueryEditorState {
export interface State {
url: string;
subscriptionUrl: string;
query: string;
// Adding undefined for backward compatibility
selectedOperation: string | undefined;
query?: string;
// Adding undefined for backward compatibility
operations: any[] | undefined;
selectedOperation?: string;
// Adding undefined for backward compatibility
operations?: any[];
httpVerb: 'POST' | 'GET' | 'PUT' | 'DELETE';
response: any;
responseTime: number;
Expand Down Expand Up @@ -69,7 +70,7 @@ export function queryReducer(state = initialState, action: query.Action): State
switch (action.type) {
case query.SET_QUERY:
case query.SET_QUERY_FROM_DB:
return Object.assign({}, state, { query: action.payload });
return Object.assign({}, state, { query: action.payload || '' });
case query.SET_URL:
case query.SET_URL_FROM_DB:
return Object.assign({}, state, { url: action.payload.url });
Expand Down

0 comments on commit f070a56

Please sign in to comment.