Skip to content

Instantly share code, notes, and snippets.

@KTruong008
Last active February 13, 2020 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KTruong008/27801ba76b0394ed8d5e9bce6a94ea96 to your computer and use it in GitHub Desktop.
Save KTruong008/27801ba76b0394ed8d5e9bce6a94ea96 to your computer and use it in GitHub Desktop.
// shared.ts
export const graphqlRequest = async <T>(
query: string,
variables = {},
): Promise<T> => {
const headers = {
...buildContentTypeHeader('application/json'),
};
const body = JSON.stringify({
query,
variables: isNil(variables) || isEmpty(variables) ? null : variables,
});
return await fetch(createGraphqlUrl(), {
method: 'POST',
headers,
body,
credentials: 'same-origin',
})
.then((responseStream: any) => {
return responseStream.json();
})
...
};
...
// app.epic.ts
Const appDataInitializationQuery = `
Query AppDataInitializationQuery {
Products {
...
`
export const appDataInitializationEpic = (
...
): Observable<StoreAction> =>
action$.pipe(
...
asyncRequest(APP_DATA_INITIALIZATION_ASYNC, (action: StoreAction) => {
return graphqlRequest(appDataInitializationQuery);
}),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment