Skip to content
A simple implementaion of apollo datasource for soap requests
JavaScript
Branch: master
Clone or download
Pull request Compare This branch is 28 commits behind RishikeshDarandale:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.github
example
src
test
.commitlintrc.yml
.editorconfig
.eslintrc.yml
.gitignore
.huskyrc.yml
.lintstagedrc
.npmrc
CONTRIBUTING.md
LICENSE
README.md
_config.yml
index.js
package-lock.json
package.json

README.md

apollo-datasource-soap

CircleCI Known Vulnerabilities Codacy Badge Codacy Badge Dependabot Status npm npm NpmLicense

A simple implementaion of apollo datasource for soap requests

Connect the SOAP based services to your Apollo server 2.0 using Data Sources

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.

class TestSoapDataSource extends SOAPDataSource {
  constructor() {
    super('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl');
  }

  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 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() {
    super('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl');
  }

  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() {
    super('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl');
  }

  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.

Contributing

⭐️ Star me on GitHub — it helps!

❤️ contribution: Here is contributing guide 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)
You can’t perform that action at this time.