weeve CLI
weeve Command Line Interface (CLI) is a bridge between you and our GraphQL backend. The main purpose of this tool is to enable weeve developers an easy interaction with our resources. Our CLI is unique as it is autogenerated based on our GraphQL schema. Therefore, if there are any changes to the structure, you just have to fetch a new schema from the server. That's it! No hardcoding new commands or other tortures.

Fetching GraphQL Schema

Once you gain an access to weeve CLI, you have to add some environmental variables:
1
GRAPHQL_URL=<schema-graphql-url>
2
API_KEY=<api-key>
3
HEADER=<x-api-key>
4
SCHEMA_PATH=src/assets/latest_schema.json # directory to save fetched schema
Copied!
Start with checking if you can access GraphQL API:
1
weeve-cli api ping
Copied!
If you don't succeed check the credentials, eventually contact us to confirm the keys. Next, you need to fetch GraphQL Schema from the server using GraphQL Introspection Query. This will download the entire GraphQL Docs containing a list of all Queries, Mutations, Subscriptions and Types defined by our backend:
1
weeve-cli api fetch
Copied!
As you notice, it should download the file with the latest schema in a directory pointed by SCHEMA_PATH environment. In order to explore supported Queries, Mutations and Subscriptions run:
1
weeve-cli schema listDocs
Copied!
This will list available commands in a form <resource> <action>. For instance, under Queries section you should see node list and you run this command as weeve-cli node list to list all registered node resources.
Moreover, you can list all supported Types:
1
weeve-cli schema listTypes
Copied!
Additionally, if you want to further investigate a specific type and see its full structure you can call it with --typeName option, i.e. to see details of Location type run:
1
weeve-cli schema listTypes --typeName=Location
Copied!

Query

Queries allow you to perform the following actions on the resources:
  • list - list all entries of a given resource, i.e. list all registered Location with: weeve-cli location list
  • read - read specific entries of a given resource, i.e. read a Location of ID 'a131cds69' with: weeve-cli location read --_id=a131cds69
  • count - count entries of a specific resource, i.e. count all Locations: weeve-cli location count
  • pagination - paginate entries of a specific resource, i.e. for Locations: weeve-cli location pagination
If you are not sure about some command you can always run --help flag to see more information about it and all required fields. For instance, a cool option is --fieldNames that allows you to see only specific fields of the entry. Location type supports 12 fields, but if you are interested only in listing locations to see their ID, date of creation and status you can look it up with this command:
weeve-cli location list --fieldNames='_id, created, status'
The following table puts together available commands for Query type:
Resource
Action
user role resource sensor mod manifest node nodestatus deployment location useraudit
read list count pagination

Mutations

Mutations enable developers to modify entries, i.e. update, create or remove:
  • batchcreate - creates batches of entries of a given resource, i.e. batch Locations: weeve-cli location batchcreate
  • update - updates fields of a chosen entry of a given resource, i.e. update status of a Location of ID 'a131cds69' to Active with: weeve-cli location update --_id=a131cds69 --status=Active
  • delete - remove an entry of a specific resource, i.e. remove Location of ID 'a131cds69': weeve-cli location delete --_id=a131cds69
  • create - create an entry of a specific resource, i.e. create a new Location in Beijing: weeve-cli location create --locationName=Beijing
  • removeall - removes all entries of a specific resource, i.e. remove all Locations from a database: weeve-cli location removeAll
If you are not sure about some command you can always run --help flag to see more information about it and all required fields.
The following table puts together available commands for Mutation type:
Resource
Action
user role resource sensor mod manifest node nodestatus deployment location useraudit
batchcreate update delete create removeall