-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include withCredentials config option to enable credentials in cross… #489
base: master
Are you sure you want to change the base?
Conversation
…site Access-Control requests for graphql driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for this PR, it will make graphql
driver much more flexible!
@@ -2,6 +2,7 @@ import { Driver, Subscriber } from '@redux-requests/core'; | |||
|
|||
interface GraphqlDriverConfig { | |||
url: string; | |||
withCredentials?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you added ...rest
in the actual implementation, could we also support here more axios options? Maybe axios
has some ready to use interface so it would not be too time-consuming?
const axiosInstance = axios.create({ | ||
baseURL: url, | ||
...rest | ||
}); | ||
|
||
return (requestConfig, requestAction, driverActions) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we also here support more axios attrs (like requestConfig.headers
for instance)? Then it would be possible to add things like withCredentials
also per request, not only globally. I think the most safe for now would be just to support requestConfig.axiosOptions
and spread it like that:
const responsePromise = axiosInstance({
cancelToken: abortSource.token,
method: 'post',
data,
headers: requestConfig.headers,
onDownloadProgress:
driverActions.setDownloadProgress &&
(progressEvent => {
if (progressEvent.lengthComputable) {
driverActions.setDownloadProgress(calculateProgress(progressEvent));
}
}),
onUploadProgress:
driverActions.setUploadProgress &&
(progressEvent => {
if (progressEvent.lengthComputable) {
driverActions.setUploadProgress(calculateProgress(progressEvent));
}
}),
...requestConfig.axiosOptions,
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update as soon as possible. I actually implemented more options in my custom driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the axios API AxiosRequestConfig
interface, I doubt if throwing all the options might be great. I considered doing this for the GraphqlDriverConfig
interface:
/*
url,
transformRequest,
transformResponse,
headers,
timeout,
withCredentials,
adapter,
auth,
xsrfCookieName,
xsrfHeaderName,
maxContentLength,
validateStatus,
maxRedirects,
socketPath,
httpAgent,
httpsAgent,
proxy,
*/
type GraphqlDriverConfig = Omit<
AxiosRequestConfig,
| 'baseURL'
| 'method'
| 'cancelToken'
| 'onDownloadProgress'
| 'onUploadProgress'
| 'data'
| 'params'
| 'responseType'
| 'paramsSerializer'
> & {
url: string;
};
Then any of the options can still be configured per request with axiosOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your research and apologies for late reply! Could we please use https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys instead of omit
? So we will be strict and new axios types won't be added without our knowledge.
Rgarding attrs I would actually support are:
- headers
- timeout
- withCredentials
- auth
- xsrfCookieName
- xsrfHeaderName
- proxy
I think only those would be handy for graphql driver, what do you think?
Then any of the options can still be configured per request with axiosOptions
That would be excellent!
In reference to Issue 487,
this is to enable
withCredentials
config option available in axios for cross-site Access-Control with credentials in requests.I used this in my project by creating custom driver to enable cookie authentication.