1.0.0 • Published 3 years ago

duplicate-operation-name v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

Duplicate GraphQL Operation Names

duplicate-operation-name is a simple cli tool that makes it easy to check if there are any duplicate operation names in GraphQL projects that use static GraphQL queries.

It can be called on individual files, or recurisvely step through directories. It is compatible with .graphql, .ts, .tsx, .js, and .jsx files.

Installation

npm install -g duplicate-operation-name

Usage

The build tool binary is called duplicate-operation-name. Running it with no other arguments should give:

Usage: duplicate-operation-name <input_path> [--graphql] [--js] [--ts]

input_path: can be a directory or file path

flags: at least one must be passed in

Results

If any duplicate operation names are found, the script will exit with an error and print:

Error: Found duplicate operation names:
   3 x myOperationName1
   2 x myOperationName2

If no duplicate operation names are found, the script will exit without error and print:

No duplicates found!

If no queries are found, the script will exit without error and print:

No queries found.

Analyzing Queries in GraphQL files (.graphql)

duplicate-operation-name queries.graphql --graphql

Analyzing Queries in TypeScript files (.ts, .tsx)

duplicate-operation-name src/index.ts --ts

Analyzing Queries in JavaScript files (.js, .jsx)

duplicate-operation-name src/index.js --js

Analyzing Queries from Folders

It is also possible to analyze a directory containing .graphql, .ts., .tsx, .js and .jsx files:

duplicate-operation-name src/ --graphql --ts --js

Acknowledgements

This is really just a repurposed version of https://github.com/apollographql/persistgraphql. Thanks to everyone who helped make that project happen.