graphql-connector-cli v0.3.6
graphql-connector-cli
Description
This CLI tool is supposed to be run within your GraphQL project. The "service" and "paths" files have to be configured as shown later, as well as your package.json
.
Installing
npm install -g graphql-connector-cli
package.json
Add the location of your services/paths files on the following section of your package.json
:
...
"graphql-connector": {
"servicesFile": "src/service_config.json",
"pathsFile": "src/service_paths_config.json"
},
...
Configuring services
Here's what your services file could look like:
{
"services": [
{
"id": "SWAPI",
"type": "HTTP",
"name": "Star Wars API",
"requestOptions": {
"host": "http://swapi.co"
}
}
]
}
Configuring paths
Here's what your paths file could look like:
{
"paths": [
{
"id": "SWAPI/films",
"service": "SWAPI",
"requestOptions": {
"path": "/api/films/{{id}}"
}
},
{
"id": "SWAPI/people",
"service": "SWAPI",
"requestOptions": {
"path": "/api/people/{{id}}"
}
},
{
"id": "SWAPI/planets",
"service": "SWAPI",
"requestOptions": {
"path": "/api/planets/{{id}}"
}
},
{
"id": "SWAPI/species",
"service": "SWAPI",
"requestOptions": {
"path": "/api/species/{{id}}"
}
},
{
"id": "SWAPI/starships",
"service": "SWAPI",
"requestOptions": {
"path": "/api/starships/{{id}}"
}
},
{
"id": "SWAPI/vehicles",
"service": "SWAPI",
"requestOptions": {
"path": "/api/vehicles/{{id}}"
}
}
]
}
Environments
You can use two types of environments with this tool (following Postman nomenclature): global environments and environments.
Global environments are environment variables that might hold your hosts/ports for example. This tool relies on the dotenv
package for this. By default, the set of environment variables passed to this process will be used.
Environments can be used to store, e.g., users of your system, and are expressed in JSON.
Environment example:
{
"idForService1": 1234,
"idForService2": "abcdef"
}
Test calls
No more copying and pasting from/to cURL/Postman/Paw. All you have to do is:
graphql-connector --call SWAPI/films --global-env .env --env user1.json "{ \"id\": 1 }"