apollo-codegen
Advanced tools
Comparing version 0.9.0 to 0.9.1
@@ -13,2 +13,4 @@ 'use strict'; | ||
exports.NoAnonymousQueries = NoAnonymousQueries; | ||
exports.NoExplicitTypename = NoExplicitTypename; | ||
exports.NoTypenameAlias = NoTypenameAlias; | ||
@@ -22,3 +24,3 @@ var _graphql = require('graphql'); | ||
function validateQueryDocument(schema, document) { | ||
var rules = [NoAnonymousQueries].concat(_graphql.specifiedRules); | ||
var rules = [NoAnonymousQueries, NoExplicitTypename, NoTypenameAlias].concat(_graphql.specifiedRules); | ||
@@ -56,9 +58,2 @@ var validationErrors = (0, _graphql.validate)(schema, document, rules); | ||
function fixNodeLocation(node) { | ||
// FIXME: Workaround for bug in graphql-js, see https://github.com/graphql/graphql-js/pull/487 | ||
if (node.loc.start === 0) { | ||
node.loc.start = 1; | ||
} | ||
} | ||
function NoAnonymousQueries(context) { | ||
@@ -68,3 +63,2 @@ return { | ||
if (!node.name) { | ||
fixNodeLocation(node); | ||
context.reportError(new _graphql.GraphQLError('Apollo iOS does not support anonymous operations', [node])); | ||
@@ -76,2 +70,24 @@ } | ||
} | ||
function NoExplicitTypename(context) { | ||
return { | ||
Field: function Field(node) { | ||
var fieldName = node.name.value; | ||
if (fieldName == "__typename") { | ||
context.reportError(new _graphql.GraphQLError('Apollo iOS inserts __typename automatically when needed, please do not include it explicitly', [node])); | ||
} | ||
} | ||
}; | ||
} | ||
function NoTypenameAlias(context) { | ||
return { | ||
Field: function Field(node) { | ||
var aliasName = node.alias && node.alias.value; | ||
if (aliasName == "__typename") { | ||
context.reportError(new _graphql.GraphQLError('Apollo iOS needs to be able to insert __typename when needed, please do not use it as an alias', [node])); | ||
} | ||
} | ||
}; | ||
} | ||
//# sourceMappingURL=validation.js.map |
{ | ||
"name": "apollo-codegen", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "Generate client code based on a GraphQL schema and query documents", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -25,2 +25,22 @@ import { assert } from 'chai' | ||
}); | ||
it(`should throw an error for ExplicitTypename.graphql`, () => { | ||
const inputPaths = [path.join(__dirname, './starwars/ExplicitTypename.graphql')]; | ||
const document = loadAndMergeQueryDocuments(inputPaths); | ||
assert.throws( | ||
() => validateQueryDocument(schema, document), | ||
'Validation of GraphQL query document failed' | ||
); | ||
}); | ||
it(`should throw an error for TypenameAlias.graphql`, () => { | ||
const inputPaths = [path.join(__dirname, './starwars/TypenameAlias.graphql')]; | ||
const document = loadAndMergeQueryDocuments(inputPaths); | ||
assert.throws( | ||
() => validateQueryDocument(schema, document), | ||
'Validation of GraphQL query document failed' | ||
); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
273636
52
5234