|
1 | 1 | import { buildClientSchema, buildSchema, introspectionFromSchema } from 'graphql'; |
2 | 2 | import { Change, CriticalityLevel, diff } from '../../src/index.js'; |
3 | | -import { findBestMatch } from '../../src/utils/string.js'; |
4 | | -import { findChangesByPath, findFirstChangeByPath } from '../../utils/testing.js'; |
5 | 3 |
|
6 | 4 | test('same schema', async () => { |
7 | 5 | const schemaA = buildSchema(/* GraphQL */ ` |
@@ -69,7 +67,7 @@ test('renamed query', async () => { |
69 | 67 |
|
70 | 68 | expect(changed).toBeDefined(); |
71 | 69 | expect(changed.criticality.level).toEqual(CriticalityLevel.Breaking); |
72 | | - expect(changed.message).toEqual(`Schema query root has changed from 'Query' to 'RootQuery'`); |
| 70 | + expect(changed.message).toEqual(`Schema query root type was changed from 'Query' to 'RootQuery'`); |
73 | 71 | }); |
74 | 72 |
|
75 | 73 | test('new field and field changed', async () => { |
@@ -767,10 +765,10 @@ test('adding root type should not be breaking', async () => { |
767 | 765 | "criticality": { |
768 | 766 | "level": "NON_BREAKING", |
769 | 767 | }, |
770 | | - "message": "Schema subscription root has changed from 'unknown' to 'Subscription'", |
| 768 | + "message": "Schema subscription type was set to 'Subscription'.", |
771 | 769 | "meta": { |
772 | 770 | "newSubscriptionTypeName": "Subscription", |
773 | | - "oldSubscriptionTypeName": "unknown", |
| 771 | + "oldSubscriptionTypeName": null, |
774 | 772 | }, |
775 | 773 | "type": "SCHEMA_SUBSCRIPTION_TYPE_CHANGED", |
776 | 774 | }, |
@@ -803,3 +801,161 @@ test('adding root type should not be breaking', async () => { |
803 | 801 | ] |
804 | 802 | `); |
805 | 803 | }); |
| 804 | + |
| 805 | +test('null old schema', async () => { |
| 806 | + const schemaA = null; |
| 807 | + |
| 808 | + const schemaB = buildSchema(/* GraphQL */ ` |
| 809 | + type Query { |
| 810 | + foo: String |
| 811 | + } |
| 812 | +
|
| 813 | + type Subscription { |
| 814 | + onFoo: String |
| 815 | + } |
| 816 | + `); |
| 817 | + |
| 818 | + const changes = await diff(schemaA, schemaB); |
| 819 | + expect(changes).toMatchInlineSnapshot(` |
| 820 | + [ |
| 821 | + { |
| 822 | + "criticality": { |
| 823 | + "level": "NON_BREAKING", |
| 824 | + }, |
| 825 | + "message": "Schema query root type was set to 'Query'.", |
| 826 | + "meta": { |
| 827 | + "newQueryTypeName": "Query", |
| 828 | + "oldQueryTypeName": null, |
| 829 | + }, |
| 830 | + "type": "SCHEMA_QUERY_TYPE_CHANGED", |
| 831 | + }, |
| 832 | + { |
| 833 | + "criticality": { |
| 834 | + "level": "NON_BREAKING", |
| 835 | + }, |
| 836 | + "message": "Schema subscription type was set to 'Subscription'.", |
| 837 | + "meta": { |
| 838 | + "newSubscriptionTypeName": "Subscription", |
| 839 | + "oldSubscriptionTypeName": null, |
| 840 | + }, |
| 841 | + "type": "SCHEMA_SUBSCRIPTION_TYPE_CHANGED", |
| 842 | + }, |
| 843 | + { |
| 844 | + "criticality": { |
| 845 | + "level": "NON_BREAKING", |
| 846 | + }, |
| 847 | + "message": "Type 'Query' was added", |
| 848 | + "meta": { |
| 849 | + "addedTypeKind": "ObjectTypeDefinition", |
| 850 | + "addedTypeName": "Query", |
| 851 | + }, |
| 852 | + "path": "Query", |
| 853 | + "type": "TYPE_ADDED", |
| 854 | + }, |
| 855 | + { |
| 856 | + "criticality": { |
| 857 | + "level": "NON_BREAKING", |
| 858 | + }, |
| 859 | + "message": "Field 'foo' was added to object type 'Query'", |
| 860 | + "meta": { |
| 861 | + "addedFieldName": "foo", |
| 862 | + "addedFieldReturnType": "String", |
| 863 | + "typeName": "Query", |
| 864 | + "typeType": "object type", |
| 865 | + }, |
| 866 | + "path": "Query.foo", |
| 867 | + "type": "FIELD_ADDED", |
| 868 | + }, |
| 869 | + { |
| 870 | + "criticality": { |
| 871 | + "level": "NON_BREAKING", |
| 872 | + }, |
| 873 | + "message": "Type 'Subscription' was added", |
| 874 | + "meta": { |
| 875 | + "addedTypeKind": "ObjectTypeDefinition", |
| 876 | + "addedTypeName": "Subscription", |
| 877 | + }, |
| 878 | + "path": "Subscription", |
| 879 | + "type": "TYPE_ADDED", |
| 880 | + }, |
| 881 | + { |
| 882 | + "criticality": { |
| 883 | + "level": "NON_BREAKING", |
| 884 | + }, |
| 885 | + "message": "Field 'onFoo' was added to object type 'Subscription'", |
| 886 | + "meta": { |
| 887 | + "addedFieldName": "onFoo", |
| 888 | + "addedFieldReturnType": "String", |
| 889 | + "typeName": "Subscription", |
| 890 | + "typeType": "object type", |
| 891 | + }, |
| 892 | + "path": "Subscription.onFoo", |
| 893 | + "type": "FIELD_ADDED", |
| 894 | + }, |
| 895 | + ] |
| 896 | + `); |
| 897 | +}); |
| 898 | + |
| 899 | +test('null new schema', async () => { |
| 900 | + const schemaA = buildSchema(/* GraphQL */ ` |
| 901 | + type Query { |
| 902 | + foo: String |
| 903 | + } |
| 904 | +
|
| 905 | + type Subscription { |
| 906 | + onFoo: String |
| 907 | + } |
| 908 | + `); |
| 909 | + |
| 910 | + const schemaB = null; |
| 911 | + |
| 912 | + const changes = await diff(schemaA, schemaB); |
| 913 | + expect(changes).toMatchInlineSnapshot(` |
| 914 | + [ |
| 915 | + { |
| 916 | + "criticality": { |
| 917 | + "level": "BREAKING", |
| 918 | + }, |
| 919 | + "message": "Schema query root type 'Query' was removed.", |
| 920 | + "meta": { |
| 921 | + "newQueryTypeName": null, |
| 922 | + "oldQueryTypeName": "Query", |
| 923 | + }, |
| 924 | + "type": "SCHEMA_QUERY_TYPE_CHANGED", |
| 925 | + }, |
| 926 | + { |
| 927 | + "criticality": { |
| 928 | + "level": "BREAKING", |
| 929 | + }, |
| 930 | + "message": "Schema subscription type 'Subscription' was removed.", |
| 931 | + "meta": { |
| 932 | + "newSubscriptionTypeName": null, |
| 933 | + "oldSubscriptionTypeName": "Subscription", |
| 934 | + }, |
| 935 | + "type": "SCHEMA_SUBSCRIPTION_TYPE_CHANGED", |
| 936 | + }, |
| 937 | + { |
| 938 | + "criticality": { |
| 939 | + "level": "BREAKING", |
| 940 | + }, |
| 941 | + "message": "Type 'Query' was removed", |
| 942 | + "meta": { |
| 943 | + "removedTypeName": "Query", |
| 944 | + }, |
| 945 | + "path": "Query", |
| 946 | + "type": "TYPE_REMOVED", |
| 947 | + }, |
| 948 | + { |
| 949 | + "criticality": { |
| 950 | + "level": "BREAKING", |
| 951 | + }, |
| 952 | + "message": "Type 'Subscription' was removed", |
| 953 | + "meta": { |
| 954 | + "removedTypeName": "Subscription", |
| 955 | + }, |
| 956 | + "path": "Subscription", |
| 957 | + "type": "TYPE_REMOVED", |
| 958 | + }, |
| 959 | + ] |
| 960 | + `); |
| 961 | +}); |
0 commit comments