https://github.com/rishikeshdarandale/apollo-datasource-soap
A simple implementaion of apollo datasource for soap requests
https://github.com/rishikeshdarandale/apollo-datasource-soap
apollo apollo-datasource apollo-datasource-soap graphql
Last synced: 5 months ago
JSON representation
A simple implementaion of apollo datasource for soap requests
- Host: GitHub
- URL: https://github.com/rishikeshdarandale/apollo-datasource-soap
- Owner: RishikeshDarandale
- License: mit
- Created: 2019-01-21T05:45:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-01T05:15:13.000Z (7 months ago)
- Last Synced: 2025-01-01T15:51:48.442Z (5 months ago)
- Topics: apollo, apollo-datasource, apollo-datasource-soap, graphql
- Language: TypeScript
- Homepage: https://rishikeshdarandale.github.io/apollo-datasource-soap/
- Size: 1.83 MB
- Stars: 12
- Watchers: 3
- Forks: 4
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# apollo-datasource-soap
[](https://circleci.com/gh/RishikeshDarandale/apollo-datasource-soap)

[](https://snyk.io/test/github/RishikeshDarandale/apollo-datasource-soap)
[](https://www.npmjs.com/package/apollo-datasource-soap)
[](https://www.npmjs.com/package/apollo-datasource-soap)
[](https://github.com/RishikeshDarandale/apollo-datasource-soap/blob/master/LICENSE)A simple implementation of apollo datasource for soap requests
Connect the SOAP based services to your Apollo server using [Data Sources][1]
`apollo-datasource-soap` versions:
- 1.x => apollo server 2.x
- 2.x => apollo server 3.x
- 3.x => apollo server 4.x# Soap Data Source
## Install
```
npm install --save apollo-dataSource-soap
```or
```
yarn add apollo-dataSource-soap
```## Usage
Define a data source by extending the `SOAPDataSource` class. You can invoke the soap method with param by invoking `invoke` method.
The cache can be initialized as specified in [apollo migration 4 guide]
```
class TestSoapDataSource extends SOAPDataSource {
constructor() {
// pass the cache as per your requirement
super('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl', {cache: new InMemoryLRUCache()});
}async willSendRequest(options) {
// override the soap endpoint for all requests
options.endpoint = 'http://www.thomas-bayer.com/axis2/services/BLZService';
// these will be used for all soap calls
options.wsdl_headers = {
Authorization: token,
}
}async getBank() {
return await this.invoke('getBank', {blz: 37050198});
}
}
```# SOAP Cache utility
SOAP is sent as HTTP POST and its a non-idempotent. Thus it can not be cached at HTTP level.
[This][4] is draft verison of document for response caching for SOAP, but did not found any implementaion of it.
Thus it make sense to client decide to cache it or not and for how much duration.
Specify the ttl to cache the SOAP response.
```
class TestSoapDataSource extends SOAPDataSource {
constructor() {
// pass the cache as per your requirement
super('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl', {cache: new InMemoryLRUCache()});
}async willSendRequest(options) {
// override the soap endpoint for all requests
options.endpoint = 'http://www.thomas-bayer.com/axis2/services/BLZService';
// these will be used for all soap calls
options.wsdl_headers = {
Authorization: token,
}
}async getBank() {
// cache the response for 1 hour
return await this.invoke('getBank', {blz: 37050198}, {ttl: 3600});
}
}
```## Decide when to cache
There might be a situation where client needs to decide the response should be cached based on response code. This can be achieved overriding the method `shouldCache` method. `shouldCache` method returns a `boolean` flag to indicate if response can be cached or not. Please take a look at below example:
```
class TestSoapDataSource extends SOAPDataSource {
constructor() {
// pass the cache as per your requirement
super('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl', {cache: new InMemoryLRUCache()});
}async willSendRequest(options) {
// override the soap endpoint for all requests
options.endpoint = 'http://www.thomas-bayer.com/axis2/services/BLZService';
// these will be used for all soap calls
options.wsdl_headers = {
Authorization: token,
}
}async getBank() {
// cache the response for 1 hour
return await this.invoke('getBank', {blz: 37050198}, {ttl: 3600});
}shouldCache(response) {
return response.code === 0 ? true : false;
}
}
```# Issue or need a new feature?
If you are experiencing a issue or wanted to add a new feature, please create a github issue [here][2].
# Contributing
:star: Star me on GitHub — it helps!
:heart: contribution: Here is [contributing guide][3] in deatil.
For impatient here are quick steps:
- **Fork** the repository
- Create **Branch** in you local repository
- while(youFinish) { **Commit** }
- **Squash** related commits.
- **Write** unit test cases for your work.
- Check the **Build** on your local.
- Raise a **Pull Request** (aka PR)[1]: https://www.apollographql.com/docs/apollo-server/features/data-sources.html
[2]: https://github.com/RishikeshDarandale/apollo-datasource-soap/issues/new
[3]: ./CONTRIBUTING.md
[4]: https://lists.w3.org/Archives/Public/www-ws/2001Aug/att-0000/ResponseCache.html
[5]: https://www.apollographql.com/docs/apollo-server/migration#datasources