-
-
Notifications
You must be signed in to change notification settings - Fork 796
/
fragmentsAreNotDuplicated.test.ts
88 lines (74 loc) · 1.71 KB
/
fragmentsAreNotDuplicated.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { graphql } from 'graphql';
import { wrapSchema } from '../src';
import { makeExecutableSchema } from '@graphql-tools/schema'
import { addMocksToSchema } from '@graphql-tools/mock';
import { ExecutionResult } from '@graphql-tools/utils';
describe('Merging schemas', () => {
test('should not throw `There can be only one fragment named "FieldName"` errors', async () => {
let originalSchema = makeExecutableSchema({
typeDefs: rawSchema,
});
originalSchema = addMocksToSchema({ schema: originalSchema });
const originalResult = await graphql(
originalSchema,
query,
undefined,
undefined,
variables,
);
assertNoDuplicateFragmentErrors(originalResult);
const transformedSchema = wrapSchema(originalSchema, []);
const transformedResult = await graphql(
transformedSchema,
query,
undefined,
undefined,
variables,
);
assertNoDuplicateFragmentErrors(transformedResult);
});
});
const rawSchema = `
type Post {
id: ID!
title: String!
owner: User!
}
type User {
id: ID!
email: String
}
type Query {
post(id: ID!): Post
}
`;
const query = `
query getPostById($id: ID!) {
post(id: $id) {
...Post
owner {
...PostOwner
email
}
}
}
fragment Post on Post {
id
title
owner {
...PostOwner
}
}
fragment PostOwner on User {
id
}
`;
const variables = {
id: 123,
};
function assertNoDuplicateFragmentErrors(result: ExecutionResult) {
// Run assertion against each array element for better test failure output.
if (result.errors != null) {
result.errors.forEach((error) => expect(error.message).toBe(''));
}
}