graphql-schema-linter
Advanced tools
Comparing version 0.0.29 to 0.0.30
@@ -9,2 +9,10 @@ # Changelog | ||
## 0.0.30 (February 12th, 2017) | ||
### Bug fixes | ||
- `defined-types-are-used` should not report errors for `Mutation` as that the naming convention for a schema's mutation root. [#94](https://github.com/cjoudrey/graphql-schema-linter/pull/94) | ||
- `defined-types-are-used` should not report unreferenced types that implement an interface that is used. [#94](https://github.com/cjoudrey/graphql-schema-linter/pull/94) | ||
- Return useful error when --stdin is specified but no schema is provided. [#96](https://github.com/cjoudrey/graphql-schema-linter/pull/96) | ||
## 0.0.29 (February 11th, 2017) | ||
@@ -11,0 +19,0 @@ |
@@ -72,2 +72,6 @@ 'use strict'; | ||
this.schema = getSchemaFromFileDescriptor(this.stdinFd); | ||
if (this.schema == null) { | ||
return null; | ||
} | ||
this.sourceMap = new _source_map.SourceMap({ stdin: this.schema }); | ||
@@ -217,3 +221,14 @@ } else if (this.options.schemaPaths) { | ||
while (true) { | ||
var n = (0, _fs.readSync)(fd, b, 0, b.length); | ||
var n = void 0; | ||
try { | ||
n = (0, _fs.readSync)(fd, b, 0, b.length); | ||
} catch (e) { | ||
if (e.code == 'EAGAIN') { | ||
console.error('The --stdin option was specified, but not schema was provided via stdin.'); | ||
} else { | ||
console.error(e.message); | ||
} | ||
return null; | ||
} | ||
if (!n) { | ||
@@ -220,0 +235,0 @@ break; |
@@ -11,3 +11,3 @@ 'use strict'; | ||
function DefinedTypesAreUsed(context) { | ||
var ignoredTypes = ['Query', 'Mutatation', 'Subscription']; | ||
var ignoredTypes = ['Query', 'Mutation', 'Subscription']; | ||
var definedTypes = []; | ||
@@ -30,3 +30,3 @@ var referencedTypes = new Set(); | ||
NamedType: function NamedType(node) { | ||
NamedType: function NamedType(node, key, parent, path, ancestors) { | ||
referencedTypes.add(node.name.value); | ||
@@ -38,2 +38,16 @@ }, | ||
definedTypes.forEach(function (node) { | ||
if (node.kind == 'ObjectTypeDefinition') { | ||
var implementedInterfaces = node.interfaces.map(function (node) { | ||
return node.name.value; | ||
}); | ||
var anyReferencedInterfaces = implementedInterfaces.some(function (interfaceName) { | ||
return referencedTypes.has(interfaceName); | ||
}); | ||
if (anyReferencedInterfaces) { | ||
return; | ||
} | ||
} | ||
if (!referencedTypes.has(node.name.value)) { | ||
@@ -40,0 +54,0 @@ context.reportError(new _validation_error.ValidationError('defined-types-are-used', 'The type `' + node.name.value + '` is defined in the ' + 'schema but not used anywhere.', [node])); |
{ | ||
"name": "graphql-schema-linter", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"description": | ||
@@ -5,0 +5,0 @@ "Command line tool and package to validate GraphQL schemas against a set of rules.", |
@@ -89,4 +89,4 @@ # graphql-schema-linter [![Travis CI](https://travis-ci.org/cjoudrey/graphql-schema-linter.svg?branch=master)](https://travis-ci.org/cjoudrey/graphql-schema-linter) [![npm version](https://badge.fury.io/js/graphql-schema-linter.svg)](https://yarnpkg.com/en/package/graphql-schema-linter) | ||
If you have both client and server schema in the same project, you'll likely need to put | ||
multiple entries in the `lint-staged` object above - one for client and one for server. Something like: | ||
If your project has `.graphql` query files and `.graphql` schema files, you'll likely need multiple entries in the | ||
`lint-staged` object - one for queries and one for schema. For example: | ||
@@ -99,3 +99,3 @@ ```json | ||
"lint-staged": { | ||
"client/*.graphql": ["graphql-schema-linter client/*.graphql"], | ||
"client/*.graphql": ["eslint . --ext .js --ext .gql --ext .graphql"], | ||
"server/*.graphql": ["graphql-schema-linter server/*.graphql"] | ||
@@ -106,2 +106,32 @@ } | ||
If you have multiple schemas in the same folder, your `lint-staged` configuration will need to be more specific, otherwise | ||
`graphql-schema-linter` will assume they are all parts of one schema. For example: | ||
**Correct:** | ||
```json | ||
{ | ||
"scripts": { | ||
"precommit": "lint-staged" | ||
}, | ||
"lint-staged": { | ||
"server/schema.public.graphql": ["graphql-schema-linter"], | ||
"server/schema.private.graphql": ["graphql-schema-linter"] | ||
} | ||
} | ||
``` | ||
**Incorrect (if you have multiple schemas):** | ||
```json | ||
{ | ||
"scripts": { | ||
"precommit": "lint-staged" | ||
}, | ||
"lint-staged": { | ||
"server/*.graphql": ["graphql-schema-linter"] | ||
} | ||
} | ||
``` | ||
## Configuration file | ||
@@ -108,0 +138,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
696979
952
301