E CLI Commands#

Use the CLI to:

  • Generate GraphQL queries specific to your Schema
  • Embed the CLI within your CI/CD process
  • Quickly store a Schema, create a Ledger, and start posting Ledger Entries

To install using Homebrew, run:

brew tap fragment-dev/tap &&\
  brew install fragment-dev/tap/fragment-cli

login

#

Authenticate with FRAGMENT.

Authentication is scoped to one FRAGMENT Workspace. If you want to authenticate with another Workspace, you must create another API Client and follow the authentication flow again.

Credentials will be written to ~/.fragment/auth.json.

Usage
fragment login \
  [--api-url=<api-url>] \
  [--client-id=<client-id>] \
  [--client-secret=<client-secret>] \
  [--oauth-scope=<oauth-scope>] \
  [--oauth-url=<oauth-url>] \
  [--test]

Optionally, run fragment login and the CLI will prompt you for the credentials.

Flags
--api-url=<api-url>The API URL for your FRAGMENT Workspace
--client-id=<client-id>The API Client ID
--client-secret=<client-secret>The API Client Secret
--oauth-scope=<oauth-scope>The OAuth Scope for your auth token
--oauth-url=<oauth-url>The OAuth URL from which to retrieve the auth token
--testIf set, tests stored credentials
Example
fragment login \
  --api-url="<api-url>" \
  --client-id="<client-id>" \
  --client-secret="<client-secret>" \
  --oauth-scope="<oauth-scope>" \
  --oauth-url="<oauth-url>"

To test the stored credentials, run:

fragment login --test

store-schema

#

Store a Schema within your FRAGMENT workspace.

Usage
fragment store-schema [-p <value>] [-v]
Flags
-p, --path=<value>[default: fragment.jsonc] Path for schema JSON file.
-v, --verboseEnable verbose mode (prints GraphQL commands)
Example
fragment store-schema \
  -p your-fragment-schema.jsonc

create-ledger

#

Create a Ledger within your FRAGMENT workspace.

Usage
fragment create-ledger \
  --ik=<ledger-ik> \
  --name=<ledger-name> \
  --schema=<schema-file>
Flags
-i, --ik=<ledger-ik>Idempotency key for createLedger
-n, --name=<ledger-name>Ledger name
-s, --schema=<schema-key>[default: fragment.jsonc] Path to the schema JSON file.
-v, --verboseEnable verbose mode (prints GraphQL commands)
Example
fragment create-ledger \
  --ik=test-ledger \
  --name="Test Ledger" \
  --schema=your-fragment-schema.jsonc

get-schema

#

Retrieve a Schema from the API for local use.

Usage
fragment get-schema \
  [--key=<schema-key>] \
  [--version=<version>] \
  [--output=<output-file>] \
  [-v]
Flags
-k, --key=<schema-key>(Optional) Key of the Schema (e.g. template-schema). If not provided, you'll be prompted to choose a Schema.
-o, --output=<output-file>Path to the JSONC schema file. Defaults to the schema key in the current directory.
--version=<version>Schema version to retrieve. Defaults to the latest version.
-v, --verboseEnable verbose mode (prints GraphQL commands)
Example

To choose the Schema from a list, run:

fragment get-schema

If providing the Schema key, run:

Providing a Schema key
fragment get-schema \
  --key=test-schema

add-ledger-entry

#

Post a Ledger Entry to your FRAGMENT Ledger.

Usage
fragment add-ledger-entry \
  --ik=<add-ledger-entry-ik> \
  --ledger.ik=<ledger-ik> \
  --type=<entry-type> \
  [--param=<parameter-value>] \
  [-v]
Flags
-i, --ik=<add-ledger-entry-ik>Idempotency key for addLedgerEntry
-l, --ledger.ik=<ledger-ik>Idempotency Key of the Ledger to post the Ledger Entry to
-t, --type=<entry-type>The type of Ledger Entry you want to post
-p, --param=<value>...The parameters for your Ledger Entry. You may specify multiple parameters by repeating the flag.
(ex: --param amount=100 --param currency=USD)
-v, --verboseEnable verbose mode (prints GraphQL commands)
Example
fragment add-ledger-entry \
  --ik=your-entry-ik \
  --ledger.ik=your-ledger-ik \
  --type=user_funds_account \
  --param='user_id="testing-user"' \
  --param='funding_amount="200"'

gen-graphql

#

Generate GraphQL queries to post Ledger Entries for a given Schema.

The generated GraphQL queries can be used to generate SDK code specific to your Schema. Read Install the SDK to learn more.

Usage
fragment gen-graphql \
  --path=<path-to-schema.jsonc> \
  --output=<output-filename.graphql>
Flags
-o, --output=<output-filename>The path for the generated file. Must end with .graphql or .gql
-p, --path=<schema-file-path>The path to your Schema file
--output-file-per-queryOutput a folder of queries, instead of a single file
--include-standard-queriesInclude the set of standard GraphQL queries in the output. This is required only if you are not using the FRAGMENT SDKs
Example
fragment gen-graphql \
  --path=your-fragment-schema.jsonc \
  --output=queries.graphql
fragment gen-graphql \
  --path=your-fragment-schema.jsonc \
  --output=generated/queries \
  --output-file-per-query

update

#

Update the FRAGMENT CLI.

Usage
fragment update [-y] [--dry-run]
Flags
-y, --yesUpdate without being prompted
--dry-runRun the update process without updating the CLI
Example
fragment update -y

token

#

Get a FRAGMENT Authentication Token.

This will print your auth token to standard output (stdout).

Usage
fragment token

help

#

Display help prompt for the CLI.

Usage
fragment help [COMMANDS]
Flags
COMMANDS...The Command (or Commands) to show help for. Ex: store-schema
Example
fragment help store-schema

workspace

#

Get the details of the Workspace this CLI is authenticated to.

Usage
fragment workspace