Skip to content

Commit

Permalink
@graphql-inspector organization (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Nov 23, 2018
1 parent 4abb873 commit 0e718e8
Show file tree
Hide file tree
Showing 87 changed files with 534 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- run: yarn test
- run: yarn build
- run: yarn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ node_modules/
dist/
yarn.lock
yarn-error.log
**/*/node_modules/
**/*/dist/
**/*/yarn.lock
**/*/yarn-error.log
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/*/dist
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.exclude": {
"**/dist": true
}
}
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# GraphQL Inspector

[![CircleCI](https://circleci.com/gh/kamilkisiela/graphql-inspector.svg?style=shield&circle-token=d1cd06aba321ee2b7bf8bd2041104643639463b0)](https://circleci.com/gh/kamilkisiela/graphql-inspector)
[![npm version](https://badge.fury.io/js/graphql-inspector.svg)](https://npmjs.com/package/graphql-inspector)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![renovate-app badge](https://img.shields.io/badge/renovate-app-blue.svg)](https://renovateapp.com/)

**GraphQL Inspector** ouputs a list of changes between two GraphQL schemas. Every change is precisely explained and marked as breaking, non-breaking or dangerous.
It helps you validate documents and fragments against a schema and even find similar or duplicated types.

![Example](./demo.gif)

## Features

Major features:
Expand All @@ -26,21 +23,14 @@ GraphQL Inspector has a **CLI** and also a **programatic API**, so you can use i
## Installation

```bash
yarn add graphql-inspector
```
# CLI
yarn add @graphql-inspector/cli

## CLI Usage

```bash
graphql-inspector diff <OLD_SCHEMA> <NEW_SCHEMA>
graphql-inspector validate <DOCUMENTS> <SCHEMA>
graphql-inspector similar <SCHEMA>
graphql-inspector serve <SCHEMA>
graphql-inspector coverage <DOCUMENTS> <SCHEMA>
graphql-inspector --help
# Core API for programatic usage
yarn add @graphql-inspector/core
```

### Examples
### CLI Usage

```bash
# Compare schemas
Expand Down Expand Up @@ -107,7 +97,7 @@ import {
InvalidDocument,
SimilarMap,
SchemaCoverage,
} from 'graphql-inspector';
} from '@graphql-inspector/core';

// diff
const changes: Change[] = diff(schemaA, schemaB);
Expand Down
2 changes: 1 addition & 1 deletion example/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
}
}
}
}
}
23 changes: 12 additions & 11 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "example",
"scripts": {
"diff": "node ../dist/cli.js diff ./schemas/schema.graphql ./schemas/new.graphql",
"diff:same": "node ../dist/cli.js diff ./schemas/schema.graphql ./schemas/schema.graphql",
"validate": "node ../dist/cli.js validate ./documents/*.graphql ./schemas/schema.graphql",
"validate:none": "node ../dist/cli.js validate ./no-documents/*.graphql ./schemas/schema.graphql",
"similar": "node ../dist/cli.js similar ./schemas/similar.graphql",
"similar:type": "node ../dist/cli.js similar ./schemas/similar.graphql --type Post",
"similar:loose": "node ../dist/cli.js similar ./schemas/similar.graphql --threshold 0.1",
"serve": "node ../dist/cli.js serve ./schemas/schema.graphql",
"coverage": "node ../dist/cli.js coverage ./documents/*.graphql ./schemas/schema.graphql",
"coverage:write": "node ../dist/cli.js coverage ./documents/*.graphql ./schemas/schema.graphql --silent --write ./coverage.json",
"open-help": "node ../dist/cli.js --help"
"graphql-inspector": "node ../packages/cli/dist/index.js",
"diff": "yarn graphql-inspector diff ./schemas/schema.graphql ./schemas/new.graphql",
"diff:same": "yarn graphql-inspector diff ./schemas/schema.graphql ./schemas/schema.graphql",
"validate": "yarn graphql-inspector validate ./documents/*.graphql ./schemas/schema.graphql",
"validate:none": "yarn graphql-inspector validate ./no-documents/*.graphql ./schemas/schema.graphql",
"similar": "yarn graphql-inspector similar ./schemas/similar.graphql",
"similar:type": "yarn graphql-inspector similar ./schemas/similar.graphql --type Post",
"similar:loose": "yarn graphql-inspector similar ./schemas/similar.graphql --threshold 0.1",
"serve": "yarn graphql-inspector serve ./schemas/schema.graphql",
"coverage": "yarn graphql-inspector coverage ./documents/*.graphql ./schemas/schema.graphql",
"coverage:write": "yarn graphql-inspector coverage ./documents/*.graphql ./schemas/schema.graphql --silent --write ./coverage.json",
"open-help": "yarn graphql-inspector --help"
}
}
5 changes: 5 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.6.0-alpha.2"
}
3 changes: 0 additions & 3 deletions lint-staged.config.js

This file was deleted.

60 changes: 22 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-inspector",
"version": "0.5.1",
"private": true,
"description": "Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.",
"keywords": [
"graphql",
Expand All @@ -9,10 +9,6 @@
"cli"
],
"sideEffects": false,
"main": "dist/index.js",
"bin": {
"graphql-inspector": "dist/cli.js"
},
"author": {
"name": "Kamil Kisiela",
"email": "kamil.kisiela@gmail.com",
Expand All @@ -24,43 +20,31 @@
"url": "kamilkisiela/graphql-inspector"
},
"scripts": {
"build": "tsc",
"test": "jest",
"format": "prettier --config .prettierrc --write \"{src,__tests__}/**/*.ts\"",
"clean": "rm -rf dist/",
"precommit": "lint-staged",
"prebuild": "npm run clean",
"prepublishOnly": "npm run build"
"build": "lerna run build",
"test": "lerna run test",
"format": "prettier --config .prettierrc --write \"**/*.{js,json,md,ts,graphql}\"",
"release": "lerna publish --exact --force-publish=\"*\"",
"release:canary": "lerna publish --force-publish=\"*\" --canary --exact",
"precommit": "lint-staged"
},
"devDependencies": {
"@types/figures": "2.0.0",
"@types/glob": "7.1.1",
"@types/graphql": "14.0.3",
"@types/indent-string": "3.0.0",
"@types/is-glob": "4.0.0",
"@types/jest": "23.3.9",
"@types/log-symbols": "2.0.0",
"@types/node-fetch": "2.1.3",
"@types/opn": "5.1.0",
"graphql-tag": "2.10.0",
"jest": "23.6.0",
"lint-staged": "8.0.4",
"prettier": "1.15.2",
"ts-jest": "23.10.4",
"typescript": "3.1.6"
"prettier": "1.15.2"
},
"dependencies": {
"apollo-server": "2.2.2",
"chalk": "2.4.1",
"commander": "2.19.0",
"figures": "2.0.0",
"glob": "7.1.3",
"graphql": "14.0.2",
"indent-string": "3.2.0",
"is-glob": "4.0.0",
"is-valid-path": "0.1.1",
"log-symbols": "2.2.0",
"node-fetch": "2.3.0",
"opn": "5.4.0"
"husky": "1.2.0",
"lerna": "3.4.3"
},
"workspaces": {
"packages": [
"packages/core",
"packages/cli"
]
},
"lint-staged": {
"*.{js,json,md,ts,graphql}": [
"prettier --write",
"git add"
]
}
}
5 changes: 5 additions & 0 deletions packages/cli/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__tests__/
src/
jest.config.js
tsconfig.json
tsconfig.test.json
1 change: 1 addition & 0 deletions packages/cli/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
21 changes: 21 additions & 0 deletions packages/cli/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Kamil Kisiela

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
98 changes: 98 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# GraphQL Inspector

[![CircleCI](https://circleci.com/gh/kamilkisiela/graphql-inspector.svg?style=shield&circle-token=d1cd06aba321ee2b7bf8bd2041104643639463b0)](https://circleci.com/gh/kamilkisiela/graphql-inspector)
[![npm version](https://badge.fury.io/js/@graphql-inspector/cli.svg)](https://npmjs.com/package/@graphql-inspector/cli)

**GraphQL Inspector** ouputs a list of changes between two GraphQL schemas. Every change is precisely explained and marked as breaking, non-breaking or dangerous.
It helps you validate documents and fragments against a schema and even find similar or duplicated types.

![Example](./demo.gif)

## Features

Major features:

- **Compares schemas**
- **Finds breaking or dangerous changes**
- **Validates documents against a schema**
- **Finds similar / duplicated types**
- **Schema coverage based on documents**
- **Serves a GraphQL server with faked data and GraphQL Playground**

GraphQL Inspector has a **CLI** and also a **programatic API**, so you can use it however you want to and even build tools on top of it.

## Installation

```bash
yarn add @graphql-inspector/cli
```

## CLI Usage

```bash
graphql-inspector diff <OLD_SCHEMA> <NEW_SCHEMA>
graphql-inspector validate <DOCUMENTS> <SCHEMA>
graphql-inspector similar <SCHEMA>
graphql-inspector serve <SCHEMA>
graphql-inspector coverage <DOCUMENTS> <SCHEMA>
graphql-inspector --help
```

### Examples

```bash
# Compare schemas
$ graphql-inspector diff OLD_SCHEMA NEW_SCHEMA

Detected the following changes (4) between schemas:

🛑 Field `name` was removed from object type `Post`
⚠️ Enum value `ARCHIVED` was added to enum `Status`
✅ Field `createdAt` was added to object type `Post`

Detected 1 breaking change


# Validate documents
$ graphql-inspector validate DOCUMENTS SCHEMA

Detected 1 invalid document:

🛑 ./documents/post.graphql:
- Cannot query field createdAtSomePoint on type Post. Did you mean createdAt?


# Find similar types
$ graphql-inspector similar SCHEMA

✅ Post
Best match (60%): BlogPost


# Serve faked GraphQL API with Playground
$ graphql-inspector serve SCHEMA

✅ Serving the GraphQL API on http://localhost:4000/


# Check coverage
$ graphql-inspector coverage DOCUMENTS SCHEMA

Schema coverage

type Query {
post x 1
}

type Post {
id x 1
title x 1
🛑 createdAt x 0
🛑 modifiedAt x 0
}

```

## License

[MIT](https://github.com/kamilkisiela/graphql-inspector/blob/master/LICENSE) © Kamil Kisiela
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions __tests__/cli/diff.ts → packages/cli/__tests__/diff.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {diff} from '../../src/cli/commands/diff';
import {ConsoleRenderer} from '../../src/cli/render';
import {diff} from '../src/commands/diff';
import {ConsoleRenderer} from '../src/render';

const oldSchema = '../assets/old.graphql';
const newSchema = '../assets/new.graphql';
const oldSchema = './assets/old.graphql';
const newSchema = './assets/new.graphql';

function hasMessage(msg: string) {
return (args: string[]) => args.join('').indexOf(msg) !== -1;
}

describe('cli/diff', () => {
describe('diff', () => {
const renderer = new ConsoleRenderer();
let spyProcessExit: jest.SpyInstance;
let spyProcessCwd: jest.SpyInstance;
Expand Down
4 changes: 2 additions & 2 deletions __tests__/cli/render.ts → packages/cli/__tests__/render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk';
import {renderChange, getSymbol} from '../../src/cli/render';
import {Change, CriticalityLevel, ChangeType} from '../../src/diff/changes/change';
import {Change, CriticalityLevel, ChangeType} from '@graphql-inspector/core';
import {renderChange, getSymbol} from '../src/render';

test('render dangerous', () => {
const change: Change = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {validate} from '../../src/cli/commands/validate';
import {ConsoleRenderer, bolderize} from '../../src/cli/render';
import {validate} from '../src/commands/validate';
import {ConsoleRenderer, bolderize} from '../src/render';

const schema = './__tests__/assets/old.graphql';
const documents = './__tests__/assets/document.graphql';
Expand All @@ -8,7 +8,7 @@ function hasMessage(msg: string) {
return (args: string[]) => args.join('').indexOf(msg) !== -1;
}

describe('cli/validate', () => {
describe('validate', () => {
const renderer = new ConsoleRenderer();
let spyProcessExit: jest.SpyInstance;
let spyEmit: jest.SpyInstance;
Expand All @@ -27,7 +27,7 @@ describe('cli/validate', () => {
test('should load graphql files', async () => {
await validate(documents, schema, {
renderer,
require: []
require: [],
});

expect(
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0e718e8

Please sign in to comment.