|
1 | 1 | import { describe, expect, test } from 'vitest'; |
2 | 2 | import { |
3 | | - DIRECTIVE_DEFINITION_BY_NAME, |
4 | 3 | FIRST_ORDINAL, |
5 | 4 | invalidDirectiveError, |
6 | 5 | invalidRepeatedDirectiveErrorMessage, |
7 | 6 | OPENFED_REQUEST_SCOPED, |
8 | 7 | OPENFED_REQUEST_SCOPED_DEFINITION, |
| 8 | + requestScopedSingleFieldWarning, |
9 | 9 | ROUTER_COMPATIBILITY_VERSION_ONE, |
10 | 10 | undefinedRequiredArgumentsErrorMessage, |
11 | 11 | } from '../../../src'; |
@@ -71,6 +71,30 @@ describe('@openfed__requestScoped tests', () => { |
71 | 71 | expect(config!.entityCaching!.requestScopedConfigurations![0].fieldName).toBe('currentLocale'); |
72 | 72 | expect(config!.entityCaching!.requestScopedConfigurations![0].l1Key).toBe('subgraph-default-a.locale'); |
73 | 73 | }); |
| 74 | + |
| 75 | + test('that a key declared on only one field still populates config but emits a warning', () => { |
| 76 | + const result = normalizeSubgraphSuccess( |
| 77 | + createSubgraphWithDefaultName(` |
| 78 | + type Query { |
| 79 | + currentUser: User @openfed__requestScoped(key: "lonely") |
| 80 | + } |
| 81 | + type User @key(fields: "id") { |
| 82 | + id: ID! |
| 83 | + } |
| 84 | + `), |
| 85 | + ROUTER_COMPATIBILITY_VERSION_ONE, |
| 86 | + ); |
| 87 | + const config = result.configurationDataByTypeName.get('Query'); |
| 88 | + expect(config!.entityCaching?.requestScopedConfigurations).toHaveLength(1); |
| 89 | + expect(config!.entityCaching!.requestScopedConfigurations![0].l1Key).toBe('subgraph-default-a.lonely'); |
| 90 | + expect(result.warnings).toStrictEqual([ |
| 91 | + requestScopedSingleFieldWarning({ |
| 92 | + subgraphName: 'subgraph-default-a', |
| 93 | + key: 'lonely', |
| 94 | + fieldCoords: 'Query.currentUser', |
| 95 | + }), |
| 96 | + ]); |
| 97 | + }); |
74 | 98 | }); |
75 | 99 |
|
76 | 100 | describe('validation tests', () => { |
|
0 commit comments