Last active
February 13, 2020 22:02
-
-
Save KTruong008/27801ba76b0394ed8d5e9bce6a94ea96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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