|
| 1 | +import {buildSchema} from 'graphql'; |
| 2 | + |
| 3 | +import {findFirstChangeByPath} from '../../utils/testing'; |
| 4 | +import {diff} from '../../src/index'; |
| 5 | +import {CriticalityLevel} from '../../src/diff/changes/change'; |
| 6 | + |
| 7 | +describe('argument', () => { |
| 8 | + describe('default value', () => { |
| 9 | + test('added', async () => { |
| 10 | + const a = buildSchema(/* GraphQL */ ` |
| 11 | + input Foo { |
| 12 | + a: String! |
| 13 | + } |
| 14 | + |
| 15 | + type Dummy { |
| 16 | + field(foo: Foo): String |
| 17 | + } |
| 18 | + `); |
| 19 | + const b = buildSchema(/* GraphQL */ ` |
| 20 | + input Foo { |
| 21 | + a: String! |
| 22 | + } |
| 23 | + |
| 24 | + type Dummy { |
| 25 | + field(foo: Foo = {a: "a"}): String |
| 26 | + } |
| 27 | + `); |
| 28 | + |
| 29 | + const change = findFirstChangeByPath(await diff(a, b), 'Dummy.field.foo'); |
| 30 | + |
| 31 | + expect(change.criticality.level).toEqual(CriticalityLevel.Dangerous); |
| 32 | + expect(change.type).toEqual('FIELD_ARGUMENT_DEFAULT_CHANGED'); |
| 33 | + expect(change.message).toEqual('Default value \'[Object: null prototype] { a: \'a\' }\' was added to argument \'foo\' on field \'Dummy.field\''); |
| 34 | + }); |
| 35 | + |
| 36 | + test('changed', async () => { |
| 37 | + const a = buildSchema(/* GraphQL */ ` |
| 38 | + input Foo { |
| 39 | + a: String! |
| 40 | + } |
| 41 | + |
| 42 | + type Dummy { |
| 43 | + field(foo: Foo = {a: "a"}): String |
| 44 | + } |
| 45 | + `); |
| 46 | + const b = buildSchema(/* GraphQL */ ` |
| 47 | + input Foo { |
| 48 | + a: String! |
| 49 | + } |
| 50 | + |
| 51 | + type Dummy { |
| 52 | + field(foo: Foo = {a: "new-value"}): String |
| 53 | + } |
| 54 | + `); |
| 55 | + |
| 56 | + const change = findFirstChangeByPath(await diff(a, b), 'Dummy.field.foo'); |
| 57 | + |
| 58 | + expect(change.criticality.level).toEqual(CriticalityLevel.Dangerous); |
| 59 | + expect(change.type).toEqual('FIELD_ARGUMENT_DEFAULT_CHANGED'); |
| 60 | + expect(change.message).toEqual('Default value for argument \'foo\' on field \'Dummy.field\' changed from \'[Object: null prototype] { a: \'a\' }\' to \'[Object: null prototype] { a: \'new-value\' }\''); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments