1.33.99 • Published 4 years ago

translation-to-graphql v1.33.99

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

translation-to-graphql

The purpose of this package is the generate a GraphQL schema from a swagger file and translation file. This GraphQL schema can then be served on an express server and queried to return the appropriate results. This library is only intended to be used for the Listen Online project. This package contains a few utility functions as well for managing the swagger files and translation files.

Getting Started

Prerequisites

  • nodejs

Installing

Run

yarn 

to install dependencies

Dependencies

This package uses a modified version of the openapi-to-graphql library. The main change is that it calls the endpoint defined in operationId, not the endpoint itself. That is, if an endpoint has name "/popular" and its operationId is "popular-get:/subreddits/popular", then the resolver function defined in the GraphQL schema will have the endpoint "/subreddits/popular" instead of "/popular".

The user can name the endpoints anything in the translation file (as long as there are no duplicates). Those endpoints names get transferred to the generated swagger file, but the underlying endpoint name still has to be saved in the operationId.

For example, the swagger and translation file could look like

let swaggerFile = {
    ...
};

let translationFile = {
    "endpoints": {
        "/subreddits/popular": {
            "popular1": {
                "get": {
                    ...
                }
            },
            "popular2" : {
                "get": {
                    ...
                }
            }
        }
        "/subreddits/hot" : {
            "hot" : {
                "get": {
                    ...
                }
            }
        }
    }
};

After generating the new swagger file, it would look like:

let newSwagger = {
    "paths": {
        "/popular1": {
            "get": {
                "opeartionId": "popular1-get:/subreddits/popular"
            },
            ...
        },
        "/popular2" : {
            "get": {
                "opeartionId": "popular2-get:/subreddits/popular"
            },
            ...
        },
        "/hot" : {
            "get": {
                "opeartionId": "hot-get:/subreddits/hot"
            },
            ...
        }
    }
}

The openapi-to-graphql library normally reads the endpoint names (e.g. /popular1, /popular2, and /hot), but those endpoints are user defined from the translation tool so they do not exist. The modified openapi-to-graphql reads the endpoints from the opeartionIDs (e.g. /subreddits/popular and /subreddits/hot) and those become the URLs in the resolver functions. This is what we want since those endpoints come from the swagger files so they actually exist. That is, the swagger files contain endpoints from the reddit APIs so they define the APIs. The endpoint names defined in the translation file from the translation tool are user-defined.

The modified library code repository is here: https://github.com/wangleex/openapi-to-graphql

Deployment

  1. Update package.json with new version number
  2. Run npm publish

Documentation

This package uses jsDoc for documentation. The documentation HTML file can be found here: index.html

Just open up the index.html and it will bring up the auto generated documentation in the web browser.

1.33.99

4 years ago

1.32.99

4 years ago

1.31.99

4 years ago

1.30.99

4 years ago

1.28.99

4 years ago

1.26.99

4 years ago

1.27.99

4 years ago

1.25.99

4 years ago

1.23.99

4 years ago

1.24.99

4 years ago

1.22.99

4 years ago

1.21.99

4 years ago

1.20.99

4 years ago

1.19.99

4 years ago

1.18.99

4 years ago

1.17.99

4 years ago

1.16.99

4 years ago

1.14.99

4 years ago

1.15.99

4 years ago

1.13.99

4 years ago

1.12.99

4 years ago

1.11.99

4 years ago

1.9.99

4 years ago

1.10.99

4 years ago

1.7.99

4 years ago

1.8.99

4 years ago

1.6.99

4 years ago

1.5.99

4 years ago

1.4.99

4 years ago

1.2.99

4 years ago

1.1.99

4 years ago

1.3.99

4 years ago

1.0.99

4 years ago

1.0.98

4 years ago

1.0.97

4 years ago

1.0.96

4 years ago

1.0.95

4 years ago

1.0.94

4 years ago

1.0.93

4 years ago

1.0.91

4 years ago

1.0.92

4 years ago

1.0.88

4 years ago

1.0.87

4 years ago

1.0.86

4 years ago

1.0.89

4 years ago

1.0.90

4 years ago

1.0.85

4 years ago

1.0.84

4 years ago

1.0.83

4 years ago

1.0.82

4 years ago

1.0.81

4 years ago

1.0.80

4 years ago

1.0.79

4 years ago

1.0.77

4 years ago

1.0.78

4 years ago

1.0.76

4 years ago

1.0.75

4 years ago

1.0.74

4 years ago

1.0.73

4 years ago

1.0.72

4 years ago

1.0.71

4 years ago

1.0.70

4 years ago

1.0.69

4 years ago

1.0.66

4 years ago

1.0.68

4 years ago

1.0.67

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.63

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.49

4 years ago

1.0.48

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.44

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.40

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.28

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.23

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.12

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago