Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/efstajas/gql-iterate
๐๐๐ช A CL tool for running the same GQL query repeatedly with variable values from a CSV.
https://github.com/efstajas/gql-iterate
cli csv graphql js nodejs npm utility
Last synced: 2 months ago
JSON representation
๐๐๐ช A CL tool for running the same GQL query repeatedly with variable values from a CSV.
- Host: GitHub
- URL: https://github.com/efstajas/gql-iterate
- Owner: efstajas
- Created: 2021-01-24T12:17:26.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-26T12:15:26.000Z (about 1 year ago)
- Last Synced: 2024-11-05T23:41:33.580Z (3 months ago)
- Topics: cli, csv, graphql, js, nodejs, npm, utility
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 13
- Watchers: 5
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ GQL-Iterate
A simple CL utility for running a query repeatedly with different variable values supplied from a CSV. Ever had to mass-query some object off GQL, but the server only supports fetching what you need one-by-one? That's what this is for!
## โคต Install
gql-iterate is available from the NPM and GitHub Packages repositories.
```
npm install @efstajas/gql-iterate -gor
yarn add @efstajas/gql-iterate -g
```## ๐ค Usage
Create a `.gql` file containing your query, which can be named anything (make sure there's only a single query specified in the file). Define the variables that you want gql-iterate to read from a CSV with the usual syntax. For example:
```gql
query GetUser($userId: String) {
user(userId: $userId) {
firstName
lastName
favoriteColor
}
}
```Next, create your input CSV file. Your file MUST be a valid CSV (with comma delimiter!) and a header that matches the variable names (without $ prefix) from your query. For example:
```
userId
1234
1235
1236
1237
```If you have more than one variable in your query, you must supply those additional variables in the CSV as well.
Now, it's time to run the queries! From the directory that contains your query and input CSV, run:
```
gql-iterate --host https://yourserver.com/graphql --input ./input.csv --query ./query.gql
```GQL-Iterate will now run all of your queries (this might take a while depending on the length of your CSV and speed of your server) and print the output to console, as one stringified JSON object per line.
## ๐ Authentication
GQL-iterate currently only supports `Authorization: Bearer` Header-based auth. To supply a bearer token, simply run the CLI with the `--bearer < your token >` option.
## Concurrency
If you want to control how many rows are processed in parallel (i.e. you have some rate limit on you API) you can use param `--concurrency`. By default it is set to 0 which means that all of the rows are processed in parallel. If you want it to work sequentially set `concurrency` to 1.