Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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