-
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.
- Loading branch information
s.vanriessen
committed
Sep 20, 2024
1 parent
69fd16c
commit b27e199
Showing
5 changed files
with
120 additions
and
31 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