-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `typeNamesMapping` option in order to update a type name --------- Co-authored-by: s.vanriessen <sander.vanriessen@bettyblocks.com>
- Loading branch information
1 parent
52b4a5d
commit 2e03d68
Showing
7 changed files
with
137 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { buildSchema } from 'graphql/index'; | ||
|
||
export default buildSchema(/* GraphQL */ ` | ||
enum EnumExample { | ||
LOREM | ||
IPSUM | ||
} | ||
type A { | ||
id: ID! | ||
str: String! | ||
email: String! | ||
} | ||
type B { | ||
id: ID! | ||
str: String! | ||
email: String! | ||
} | ||
type C { | ||
id: ID! | ||
str: String! | ||
enum: EnumExample! | ||
D: D! | ||
} | ||
type D { | ||
nested: C! | ||
} | ||
`); |
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,36 @@ | ||
import { plugin } from '../../src'; | ||
import testSchema from './schema'; | ||
|
||
it('should support typeNamesMapping', async () => { | ||
const result = await plugin(testSchema, [], { | ||
typesFile: './types/graphql.ts', | ||
typeNamesMapping: { A: 'RenamedAType' }, | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toContain("import { A as RenamedAType, B, C, D, EnumExample } from './types/graphql';"); | ||
}); | ||
|
||
it('should support typeNamesMapping with circular relationships', async () => { | ||
const result = await plugin(testSchema, [], { | ||
typesFile: './types/graphql.ts', | ||
typeNamesMapping: { D: 'RenamedDType' }, | ||
terminateCircularRelationships: 'immediate', | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toContain("import { A, B, C, D as RenamedDType, EnumExample } from './types/graphql';"); | ||
expect(result).toContain( | ||
"D: overrides && overrides.hasOwnProperty('D') ? overrides.D! : relationshipsToOmit.has('D') ? {} as DAsRenamedDType : aD({}, relationshipsToOmit),", | ||
); | ||
}); | ||
|
||
it('should not support typeNamesMapping when enum type is given', async () => { | ||
const result = await plugin(testSchema, [], { | ||
typesFile: './types/graphql.ts', | ||
typeNamesMapping: { EnumExample: 'RenamedEnum' }, | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toContain("import { A, B, C, D, EnumExample } from './types/graphql';"); | ||
}); |
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
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