|
| 1 | +import { describe, it } from 'mocha'; |
| 2 | + |
| 3 | +import { KnownOperationTypesRule } from '../rules/KnownOperationTypesRule.js'; |
| 4 | + |
| 5 | +import { expectValidationErrors } from './harness.js'; |
| 6 | + |
| 7 | +function expectErrors(queryStr: string) { |
| 8 | + return expectValidationErrors(KnownOperationTypesRule, queryStr); |
| 9 | +} |
| 10 | + |
| 11 | +function expectValid(queryStr: string) { |
| 12 | + expectErrors(queryStr).toDeepEqual([]); |
| 13 | +} |
| 14 | + |
| 15 | +describe('Validate: Known operation types', () => { |
| 16 | + it('one known operation', () => { |
| 17 | + expectValid(` |
| 18 | + { field } |
| 19 | + `); |
| 20 | + }); |
| 21 | + |
| 22 | + it('unknown mutation operation', () => { |
| 23 | + expectErrors(` |
| 24 | + mutation { field } |
| 25 | + `).toDeepEqual([ |
| 26 | + { |
| 27 | + message: 'The mutation operation is not supported by the schema.', |
| 28 | + locations: [{ line: 2, column: 7 }], |
| 29 | + }, |
| 30 | + ]); |
| 31 | + }); |
| 32 | + |
| 33 | + it('unknown subscription operation', () => { |
| 34 | + expectErrors(` |
| 35 | + subscription { field } |
| 36 | + `).toDeepEqual([ |
| 37 | + { |
| 38 | + message: 'The subscription operation is not supported by the schema.', |
| 39 | + locations: [{ line: 2, column: 7 }], |
| 40 | + }, |
| 41 | + ]); |
| 42 | + }); |
| 43 | + |
| 44 | + it('mixture of known and unknown operations', () => { |
| 45 | + expectErrors(` |
| 46 | + query { field } |
| 47 | + mutation { field } |
| 48 | + subscription { field } |
| 49 | + `).toDeepEqual([ |
| 50 | + { |
| 51 | + message: 'The mutation operation is not supported by the schema.', |
| 52 | + locations: [{ line: 3, column: 7 }], |
| 53 | + }, |
| 54 | + { |
| 55 | + message: 'The subscription operation is not supported by the schema.', |
| 56 | + locations: [{ line: 4, column: 7 }], |
| 57 | + }, |
| 58 | + ]); |
| 59 | + }); |
| 60 | +}); |
0 commit comments