generate-multifields
(gmf
) is a CLI library to help generate multiple fields of
a given input format of your GraphQL queries or mutations, by repeating them for
a number of times.
There was an instance I had to generate hundreds of queries or mutations that run by IDs. I needed a tool to generate them with a given input.
"But you could do this with a small shell script!"
Yes. It was also intended for me to play with Cobra and GitHub Actions.
Get the latest binary for your OS/Architecture from the
Releases tab.
The following is the curl
instructions for macOS:
$ curl -L https://github.com/yanyi/generate-multifields/releases/latest/download/gmf-darwin_x86_64 > gmf && \
chmod +x gmf && \
mv gmf /usr/local/bin
$ which gmf
/usr/local/bin/gmf
Using Docker for released versions:
$ docker pull yanyi/generate-multifields:0.1.0
0.1.0: Pulling from yanyi/generate-multifields
Development Version
Clone the repository and run:
$ go build -i -o gmf && mv gmf /usr/local/bin
$ which gmf
/usr/local/bin/gmf
$ docker pull yanyi/generate-multifields:latest
latest: Pulling from yanyi/generate-multifields
Using a text file, the CLI looks for instances of $id
and replaces it with
the IDs when running the mutations
command. Here is an example of a text file:
hero$id: updateHeroLocation(id: $id, location: "Missing") {
id
location
}
For non-Docker, running the CLI is as simple as:
$ gmf mutations -s 10 -e 15 -f hero.txt
For Docker, mount the working directory as volume (-v
flag):
$ docker run --rm -v $(pwd):/tmp yanyi/generate-multifields:latest \
mutations -s 10 -e 15 -f /tmp/hero.txt
Tip for Docker users - Add an alias
for the Docker run instruction:
alias gmf="docker run --rm -v $(pwd):/tmp yanyi/generate-multifields:latest"
As of the current version, gmf
allows generating for
GraphQL mutations.
Run by entering a start ID and end ID, together with an input file:
$ gmf mutations -s 10 -e 15 -f hero.txt
The CLI generates the output like:
mutation {
hero10: updateHeroLocation(id: 10, location: "Missing") {
id
location
}
... (redacted for brevity)
hero15: updateHeroLocation(id: 15, location: "Missing") {
id
location
}
}