Skip to content
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

Refactor type generation #19

Merged
merged 6 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 8 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ Create a GraphQL schema from a WSDL-defined SOAP endpoint.
The created GraphQL schema contains all types declared in the WSDL and provides all operations of
the SOAP endpoint as GraphQL mutation fields. This enables you to re-publish a SOAP endpoint as a
GraphQL server. This might be convenient for clients, that already handle GraphQL and do not want to
handle SOAP. But note: The existence of this package should not necessarily encourage you to do this
... but it is possible.
handle SOAP.

This package is fully dependend on the [node-soap package](https://github.com/vpulim/node-soap). It
will only work in a Node.js environment.

Checkout [soap-graphql-demo](https://github.com/sevenclev/node-soap-graphql-demo) for a quick demo.
## Usage

Main entry point is the function
`soapGraphqlSchema(options: SoapGraphqlOptions | string): Promise<GraphQLSchema>`

See code comments for more details.

### Example (TypeScript)
### Example

```typescript
import * as express from 'express';
Expand All @@ -36,32 +40,3 @@ soapGraphqlSchema('http://<<url to wsdl>>').then((schema: GraphQLSchema) => {
});
});
```

## Usage

Main entry point is the function
`soapGraphqlSchema(options: SoapGraphqlOptions | string): Promise<GraphQLSchema>`

See code comments for more details.

## Limitations and Issues

### Supported WSDLs

There is no guarantee that this package will work with every valid WSDL.

[node-soap-graphql.spec](spec/node-soap-graphql.spec.ts) lists SOAP endpoints that were tested with
this package. It also shows how to configure custom behavior for SOAP endpoints.

Feel free to post an issue (or better yet: create a pull request with a test case) if this package
does not work with your SOAP endpoint.

### XSD features

WSDL, and especially the XSD-based schema section,
[allows a wide variety of options to define primitive types](https://www.w3.org/TR/xmlschema-2/#built-in-datatypes).
Handling of these options are only implemented in the most basic way;
[see `DefaultTypeResolver`](src/soap2graphql/custom-type-resolver.ts).

In most cases you can handle the specifics of your SOAP endpoint by implementing a
[`CustomTypeResolver`](src/soap2graphql/custom-type-resolver.ts).
27 changes: 27 additions & 0 deletions dev/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { soapGraphqlSchema } from '../src';
import { createHandler } from 'graphql-http/lib/use/http';
import * as http from 'http';

// http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL
// http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL
// https://www.uid-wse.admin.ch/V5.0/PublicServices.svc?WSDL
// https://ws.ecotransit.org/ETWStandard?wsdl
// https://ec.europa.eu/taxation_customs/dds2/eos/validation/services/validation?wsdl

soapGraphqlSchema({
debug: true,
createClient: {
url: 'https://ws.ecotransit.org/ETWStandard?wsdl',
},
}).then((schema) => {
const handler = createHandler({ schema });
const server = http.createServer((req, res) => {
if (req.url.startsWith('/graphql')) {
handler(req, res);
} else {
res.writeHead(404).end();
}
});
server.listen(4000);
console.log(`serving graphql on http://localhost:4000/graphql`);
});
2 changes: 2 additions & 0 deletions dev/start-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('ts-node').register({ lazy: true });
require('./index');
Loading