react-native-oauth
react-native-oauth copied to clipboard
Support for JSON body (GraphQL support)
I use this package for a Github integration in a React Native app. The authorization process was no problem. But when I tried to use the makeRequest function with the new Github GraphQL API I faced a problem: I need to send JSON in the request body. Looking at the Readme, there is no documented way to configure the request body. Looking at the code, I saw that you can pass a 'body' key with an object value in the options argument. But the keys of that object always seem to be appended as Multipart, and there is no way to define a Text or JSON body.
What I want to achieve is something like this:
const response = await manager.makeRequest('github', 'https://api.github.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
Accept: 'application/vnd.github.v4+json'
},
body: {
query: 'query { viewer { login }}'
}
})
Or rather as a plain string:
const response = await manager.makeRequest('github', 'https://api.github.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
Accept: 'application/vnd.github.v4+json'
},
body: '{query: \'query { viewer { login }}\'}'
})