Skip to content

Commit

Permalink
Prevent infinite loop on invalid introspection (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 6, 2018
1 parent 6963fc8 commit 6b033c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/utilities/__tests__/buildClientSchema-test.js
Expand Up @@ -844,4 +844,41 @@ describe('Type System: build schema from introspection', () => {
buildClientSchema(introspection);
});
});

describe('prevents infinite recursion on invalid introspection', () => {
it('recursive interfaces', () => {
const introspection = {
__schema: {
types: [
{
name: 'Foo',
kind: 'OBJECT',
fields: [],
interfaces: [{ name: 'Foo' }],
},
],
},
};
expect(() => buildClientSchema(introspection)).to.throw(
'Expected Foo to be a GraphQL Interface type.',
);
});

it('recursive union', () => {
const introspection = {
__schema: {
types: [
{
name: 'Foo',
kind: 'UNION',
possibleTypes: [{ name: 'Foo' }],
},
],
},
};
expect(() => buildClientSchema(introspection)).to.throw(
'Expected Foo to be a GraphQL Object type.',
);
});
});
});
4 changes: 2 additions & 2 deletions src/utilities/buildClientSchema.js
Expand Up @@ -221,7 +221,7 @@ export function buildClientSchema(
return new GraphQLObjectType({
name: objectIntrospection.name,
description: objectIntrospection.description,
interfaces: objectIntrospection.interfaces.map(getInterfaceType),
interfaces: () => objectIntrospection.interfaces.map(getInterfaceType),
fields: () => buildFieldDefMap(objectIntrospection),
});
}
Expand All @@ -248,7 +248,7 @@ export function buildClientSchema(
return new GraphQLUnionType({
name: unionIntrospection.name,
description: unionIntrospection.description,
types: unionIntrospection.possibleTypes.map(getObjectType),
types: () => unionIntrospection.possibleTypes.map(getObjectType),
});
}

Expand Down

0 comments on commit 6b033c2

Please sign in to comment.