Skip to content

Commit

Permalink
Merge branch 'staging' into dependabot/npm_and_yarn/handlebars-4.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Dec 28, 2019
2 parents 91dfcd3 + 83364f6 commit 42de7ba
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/app/effects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { debug } from '../utils/logger';
import { generateCurl } from 'app/utils/curl';

interface EffectResponseData {
state: fromRoot.State;
data: fromRoot.PerWindowState;
windowId: string;
action: any;
Expand All @@ -53,7 +54,7 @@ export class QueryEffects {
.pipe(
ofType(queryActions.SEND_QUERY_REQUEST, queryActions.CANCEL_QUERY_REQUEST),
withLatestFrom(this.store, (action: queryActions.Action, state: fromRoot.State) => {
return { data: state.windows[action.windowId], windowId: action.windowId, action };
return { state, data: state.windows[action.windowId], windowId: action.windowId, action };
}),
switchMap(response => {

Expand Down Expand Up @@ -179,6 +180,7 @@ export class QueryEffects {
method: response.data.query.httpVerb,
selectedOperation,
files: response.data.variables.files,
withCredentials: response.state.settings['request.withCredentials'],
})
.pipe(
map(res => {
Expand Down Expand Up @@ -302,7 +304,7 @@ export class QueryEffects {
.pipe(
ofType(queryActions.SEND_INTROSPECTION_QUERY_REQUEST),
withLatestFrom(this.store, (action: queryActions.Action, state: fromRoot.State) => {
return { data: state.windows[action.windowId], windowId: action.windowId, action };
return { state, data: state.windows[action.windowId], windowId: action.windowId, action };
}),
switchMap(response => {
return this.getPrerequestTransformedData$(response);
Expand Down Expand Up @@ -332,7 +334,8 @@ export class QueryEffects {
return this.gqlService
.getIntrospectionRequest(url, {
method: response.data.query.httpVerb,
headers
headers,
withCredentials: response.state.settings['request.withCredentials'],
})
.pipe(
catchError((err: any) => {
Expand Down Expand Up @@ -430,7 +433,7 @@ export class QueryEffects {
.pipe(
ofType(queryActions.START_SUBSCRIPTION),
withLatestFrom(this.store, (action: queryActions.Action, state: fromRoot.State) => {
return { data: state.windows[action.windowId], windowId: action.windowId, action };
return { state, data: state.windows[action.windowId], windowId: action.windowId, action };
}),
switchMap(response => {
return this.getPrerequestTransformedData$(response);
Expand Down
3 changes: 2 additions & 1 deletion src/app/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ export const keySerializer = (key: string) => `${getAltairInstanceStorageNamespa

export function localStorageSyncReducer(_reducer: ActionReducer<any>): ActionReducer<any> {
return localStorageSync({
keys: ['windows', 'windowsMeta', 'settings', 'environments'],
keys: [ 'windows', 'windowsMeta', 'settings', 'environments' ],
rehydrate: true,
storage: performantLocalStorage,
restoreDates: false,
// syncCondition: (state) => console.log(state),
storageKeySerializer: keySerializer
})(_reducer);
Expand Down
5 changes: 5 additions & 0 deletions src/app/reducers/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export interface State {
* Specifies a list of enabled plugins (requires enableExperimental to be true)
*/
'plugin.list'?: string[];

/**
* Specifies if requests should be sent with credentials (with cookies) or not
*/
'request.withCredentials'?: boolean;
}

export const getInitialState = (): State => {
Expand Down
34 changes: 28 additions & 6 deletions src/app/services/gql/gql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { SelectedOperation } from 'app/reducers/query/query';
interface SendRequestOptions {
query: string;
method: string;
withCredentials?: boolean;
variables?: string;
headers?: fromHeaders.Header[];
files?: fromVariables.FileVariable[];
Expand Down Expand Up @@ -100,7 +101,14 @@ export class GqlService {
* @param query
* @param vars
*/
_send(query: string, vars?: string, selectedOperation?: SelectedOperation, files?: fromVariables.FileVariable[]) {
_send({
query,
variables,
selectedOperation,
files,
withCredentials,
}: Omit<SendRequestOptions, 'method'>,
) {
const data = { query, variables: {}, operationName: (null as SelectedOperation) };
let body: FormData | string | undefined;
let params: HttpParams | undefined;
Expand All @@ -111,9 +119,9 @@ export class GqlService {
}

// If there is a variables option, add it to the data
if (vars) {
if (variables) {
try {
data.variables = JSON.parse(vars);
data.variables = JSON.parse(variables);
} catch (err) {
// Notify the user about badly written variables.
debug.error(err);
Expand Down Expand Up @@ -153,6 +161,7 @@ export class GqlService {
params,
headers,
observe: 'response',
withCredentials,
})
.pipe(
catchError((err: HttpErrorResponse) => {
Expand Down Expand Up @@ -185,8 +194,14 @@ export class GqlService {
* @param query
* @param vars
*/
send(query: string, vars?: string, selectedOperation?: string, files?: fromVariables.FileVariable[]) {
return this._send(query, vars, selectedOperation, files).pipe(map(res => res.body));
send(query: string, vars?: string, selectedOperation?: string, files?: fromVariables.FileVariable[], withCredentials?: boolean) {
return this._send({
query,
variables: vars,
selectedOperation,
files,
withCredentials,
}).pipe(map(res => res.body));
}

sendRequest(url: string, opts: SendRequestOptions) {
Expand All @@ -197,7 +212,13 @@ export class GqlService {
// Skip json default headers for files
.setHeaders(opts.headers, { skipDefaults: this.isGETRequest(opts.method) || !!(files && files.length) });

return this._send(opts.query, opts.variables, opts.selectedOperation, files);
return this._send({
query: opts.query,
variables: opts.variables,
selectedOperation: opts.selectedOperation,
files: opts.files,
withCredentials: opts.withCredentials,
});
}

isGETRequest(method = this.method) {
Expand Down Expand Up @@ -251,6 +272,7 @@ export class GqlService {
query: getIntrospectionQuery(),
headers: opts.headers,
method: opts.method,
withCredentials: opts.withCredentials,
variables: '{}',
};
return this.sendRequest(url, requestOpts).pipe(
Expand Down

0 comments on commit 42de7ba

Please sign in to comment.