1 | import { prefixTransform } from '../src';
|
2 | import { buildSchema, printSchema, GraphQLSchema } from 'graphql';
|
3 |
|
4 | describe('prefix', () => {
|
5 | let schema: GraphQLSchema;
|
6 |
|
7 | beforeEach(() => {
|
8 | schema = buildSchema( `
|
9 | type Query {
|
10 | user: User!
|
11 | }
|
12 |
|
13 | type User {
|
14 | id: ID!
|
15 | }
|
16 | `);
|
17 | });
|
18 |
|
19 | it('should prefix all schema types when prefix is specified explicitly', async () => {
|
20 | const newSchema = await prefixTransform({
|
21 | schema,
|
22 | config: {
|
23 | type: 'prefix',
|
24 | prefix: 'T_'
|
25 | }
|
26 | });
|
27 |
|
28 | expect(newSchema.getType('User')).toBeUndefined();
|
29 | expect(newSchema.getType('T_User')).toBeDefined();
|
30 | expect(printSchema(newSchema)).toMatchSnapshot();
|
31 | });
|
32 |
|
33 | it('should not modify root types', async () => {
|
34 | const newSchema = await prefixTransform({
|
35 | schema,
|
36 | config: {
|
37 | type: 'prefix',
|
38 | prefix: 'T_'
|
39 | }
|
40 | });
|
41 |
|
42 | expect(newSchema.getType('Query')).toBeDefined();
|
43 | expect(newSchema.getType('T_Query')).toBeUndefined();
|
44 | });
|
45 |
|
46 | it('should use apiName when its available', async () => {
|
47 | const newSchema = await prefixTransform({
|
48 | schema,
|
49 | apiName: 'MyApi',
|
50 | config: {
|
51 | type: 'prefix'
|
52 | }
|
53 | });
|
54 |
|
55 | expect(newSchema.getType('Query')).toBeDefined();
|
56 | expect(newSchema.getType('User')).toBeUndefined();
|
57 | expect(newSchema.getType('MyApi_User')).toBeDefined();
|
58 | });
|
59 |
|
60 | it('should allow to ignore types', async () => {
|
61 | const newSchema = await prefixTransform({
|
62 | schema,
|
63 | config: {
|
64 | prefix: 'T_',
|
65 | ignore: ['User'],
|
66 | type: 'prefix'
|
67 | }
|
68 | });
|
69 |
|
70 | expect(newSchema.getType('Query')).toBeDefined();
|
71 | expect(newSchema.getType('User')).toBeDefined();
|
72 | });
|
73 | });
|