This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
forked from ardatan/graphql-tools
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(healing): empty types should be pruned even if fields of those ty…
…pes still exist Fixes #37.
- Loading branch information
Showing
3 changed files
with
51 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* tslint:disable:no-unused-expression */ | ||
|
||
import { expect } from 'chai'; | ||
|
||
import { healSchema } from '../utils'; | ||
import { makeExecutableSchema } from '../makeExecutableSchema'; | ||
import { GraphQLObjectType, GraphQLObjectTypeConfig } from 'graphql'; | ||
|
||
describe('heal', () => { | ||
it('should prune empty types', () => { | ||
const schema = makeExecutableSchema({ | ||
typeDefs: ` | ||
type WillBeEmptyObject { | ||
willBeRemoved: String | ||
} | ||
type Query { | ||
someQuery: WillBeEmptyObject | ||
} | ||
` | ||
}); | ||
const originalTypeMap = schema.getTypeMap(); | ||
|
||
const config = originalTypeMap['WillBeEmptyObject'].toConfig() as GraphQLObjectTypeConfig<any, any>; | ||
originalTypeMap['WillBeEmptyObject'] = new GraphQLObjectType({ | ||
...config, | ||
fields: {}, | ||
}); | ||
|
||
healSchema(schema); | ||
|
||
const healedTypeMap = schema.getTypeMap(); | ||
expect(healedTypeMap).not.to.haveOwnProperty('WillBeEmptyObject'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters