|
| 1 | +import { print } from 'graphql'; |
| 2 | +import gql from 'graphql-tag'; |
| 3 | +import { |
| 4 | + assertValidatorAcceptsAndDoesNotWarn, |
| 5 | + assertValidatorRejects, |
| 6 | + assertValidatorWarns, |
| 7 | +} from './helpers'; |
| 8 | + |
| 9 | +describe('system field override validation', () => { |
| 10 | + it('is valid on non redundant system fields', () => { |
| 11 | + assertValidatorAcceptsAndDoesNotWarn( |
| 12 | + print(gql` |
| 13 | + type Root @rootEntity { |
| 14 | + id: ID @key |
| 15 | + createdAt: DateTime @hidden |
| 16 | + dummy: String |
| 17 | + } |
| 18 | +
|
| 19 | + type Root2 @rootEntity { |
| 20 | + id: ID @hidden |
| 21 | + updatedAt: DateTime @hidden |
| 22 | + dummy: String |
| 23 | + } |
| 24 | + `), |
| 25 | + ); |
| 26 | + }); |
| 27 | + |
| 28 | + it('warns on redundant system field "id"', () => { |
| 29 | + assertValidatorWarns( |
| 30 | + print(gql` |
| 31 | + type Root @rootEntity { |
| 32 | + id: ID |
| 33 | + dummy: String |
| 34 | + } |
| 35 | + `), |
| 36 | + 'Manually declaring system field "id" is redundant. Either add a suitable directive or consider removing the field', |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + it('warns on redundant system field "createdAt"', () => { |
| 41 | + assertValidatorWarns( |
| 42 | + print(gql` |
| 43 | + type Root @rootEntity { |
| 44 | + createdAt: DateTime |
| 45 | + dummy: String |
| 46 | + } |
| 47 | + `), |
| 48 | + 'Manually declaring system field "createdAt" is redundant. Either add a suitable directive or consider removing the field', |
| 49 | + ); |
| 50 | + }); |
| 51 | + |
| 52 | + it('warns on redundant system field "updatedAt"', () => { |
| 53 | + assertValidatorWarns( |
| 54 | + print(gql` |
| 55 | + type Root @rootEntity { |
| 56 | + updatedAt: DateTime |
| 57 | + dummy: String |
| 58 | + } |
| 59 | + `), |
| 60 | + 'Manually declaring system field "updatedAt" is redundant. Either add a suitable directive or consider removing the field', |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + it('errors on system field "id" type mismatch', () => { |
| 65 | + assertValidatorRejects( |
| 66 | + print(gql` |
| 67 | + type Root @rootEntity { |
| 68 | + id: String |
| 69 | + dummy: String |
| 70 | + } |
| 71 | + `), |
| 72 | + 'System field "id" must be of type "ID"', |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + it('errors on system field "createdAt" type mismatch', () => { |
| 77 | + assertValidatorRejects( |
| 78 | + print(gql` |
| 79 | + type Root @rootEntity { |
| 80 | + createdAt: String |
| 81 | + dummy: String |
| 82 | + } |
| 83 | + `), |
| 84 | + 'System field "createdAt" must be of type "DateTime"', |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + it('errors on system field "updatedAt" type mismatch', () => { |
| 89 | + assertValidatorRejects( |
| 90 | + print(gql` |
| 91 | + type Root @rootEntity { |
| 92 | + updatedAt: String |
| 93 | + dummy: String |
| 94 | + } |
| 95 | + `), |
| 96 | + 'System field "updatedAt" must be of type "DateTime"', |
| 97 | + ); |
| 98 | + }); |
| 99 | + |
| 100 | + it('errors on not allowed directives on system fields', () => { |
| 101 | + assertValidatorRejects( |
| 102 | + print(gql` |
| 103 | + type Root @rootEntity { |
| 104 | + id: ID @relation |
| 105 | + dummy: String |
| 106 | + } |
| 107 | + `), |
| 108 | + 'Directive "@relation" is not allowed on system field "id" and will be discarded', |
| 109 | + ); |
| 110 | + }); |
| 111 | +}); |
0 commit comments