Skip to content

Commit f8efb71

Browse files
committed
added weight function test for custom object weights
1 parent a0ef8b7 commit f8efb71

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/analysis/weightFunction.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ describe('Weight Function correctly parses Argument Nodes if', () => {
3232
JEDI
3333
}`);
3434

35+
// building the typeWeights object here since we're testing the weight function created in
36+
// the typeWeights object
3537
const typeWeights: TypeWeightObject = buildTypeWeightsFromSchema(schema);
3638

3739
describe('a default value is provided in the schema', () => {
@@ -76,6 +78,15 @@ describe('Weight Function correctly parses Argument Nodes if', () => {
7678
});
7779
});
7880

81+
test('a custom object weight was configured', () => {
82+
const customTypeWeights: TypeWeightObject = buildTypeWeightsFromSchema(schema, {
83+
object: 3,
84+
});
85+
const query = `query { heroes(episode: NEWHOPE, first: 3) { stars, episode } }`;
86+
const queryAST: DocumentNode = parse(query);
87+
expect(getQueryTypeComplexity(queryAST, {}, customTypeWeights)).toBe(10);
88+
});
89+
7990
xtest('an invalid arg type is provided', () => {
8091
const query = `query { heroes(episode: NEWHOPE, first = 3) { stars, episode } }`;
8192
const queryAST: DocumentNode = parse(query);

0 commit comments

Comments
 (0)