Skip to content

Commit

Permalink
Add special case for legacy servers.
Browse files Browse the repository at this point in the history
Much older versions of GraphQL use `__configs__` as part of a pseudo-introspection meta programming layer. While this is technically against the spec, this adds temporary support.
  • Loading branch information
leebyron committed Dec 17, 2017
1 parent 0d66e29 commit f051112
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/utilities/__tests__/assertValidName-test.js
Expand Up @@ -23,4 +23,8 @@ describe('assertValidName()', () => {
it('throws for names with invalid characters', () => {
expect(() => assertValidName('>--()-->')).to.throw(/Names must match/);
});

it('does not throw for legacy servers that use __configs__ introspection', () => {
expect(() => assertValidName('__configs__')).not.to.throw();
});
});
10 changes: 9 additions & 1 deletion src/utilities/assertValidName.js
Expand Up @@ -32,7 +32,15 @@ export function isValidNameError(
node?: ASTNode | void,
): GraphQLError | void {
invariant(typeof name === 'string', 'Expected string');
if (name.length > 1 && name[0] === '_' && name[1] === '_') {
if (
name.length > 1 &&
name[0] === '_' &&
name[1] === '_' &&
// Note: this special case is not part of the spec and exists only to
// support legacy server configurations. Do not rely on this special case
// as it may be removed at any time.
name !== '__configs__'
) {
return new GraphQLError(
`Name "${name}" must not begin with "__", which is reserved by ` +
'GraphQL introspection.',
Expand Down

0 comments on commit f051112

Please sign in to comment.