|
1 | 1 | import { setupMockData, User, Profile, Post, Tariff, Category, Tag } from "../support/mock-data"; |
2 | 2 | import Context from "../../src/common/context"; |
3 | 3 | import { recordGraphQLRequest } from "../support/helpers"; |
| 4 | +import gql from "graphql-tag"; |
4 | 5 |
|
5 | 6 | let store: any; |
6 | 7 | let vuexOrmGraphQL; |
@@ -815,6 +816,42 @@ mutation SendSms($to: String!, $text: String!) { |
815 | 816 | sendSms(to: $to, text: $text) { |
816 | 817 | delivered |
817 | 818 | } |
| 819 | +} |
| 820 | + `.trim() + "\n" |
| 821 | + ); |
| 822 | + }); |
| 823 | + |
| 824 | + test("also accepts GraphQL AST DocumentNode", async () => { |
| 825 | + let result; |
| 826 | + |
| 827 | + const query = gql` |
| 828 | + mutation SendSms($to: String!, $text: String!) { |
| 829 | + sendSms(to: $to, text: $text) { |
| 830 | + delivered |
| 831 | + } |
| 832 | + } |
| 833 | + `; |
| 834 | + |
| 835 | + const request = await recordGraphQLRequest(async () => { |
| 836 | + result = await store.dispatch("entities/simpleMutation", { |
| 837 | + query, |
| 838 | + variables: { to: "+4912345678", text: "GraphQL is awesome!" } |
| 839 | + }); |
| 840 | + }); |
| 841 | + |
| 842 | + expect(request!.variables).toEqual({ to: "+4912345678", text: "GraphQL is awesome!" }); |
| 843 | + expect(result).toEqual({ |
| 844 | + sendSms: { |
| 845 | + __typename: "SmsStatus", // TODO: this could removed by Vuex-ORM-GraphQL IMHO |
| 846 | + delivered: true |
| 847 | + } |
| 848 | + }); |
| 849 | + expect(request!.query).toEqual( |
| 850 | + ` |
| 851 | +mutation SendSms($to: String!, $text: String!) { |
| 852 | + sendSms(to: $to, text: $text) { |
| 853 | + delivered |
| 854 | + } |
818 | 855 | } |
819 | 856 | `.trim() + "\n" |
820 | 857 | ); |
@@ -855,6 +892,44 @@ query Status { |
855 | 892 | smsGateway |
856 | 893 | paypalIntegration |
857 | 894 | } |
| 895 | +} |
| 896 | + `.trim() + "\n" |
| 897 | + ); |
| 898 | + }); |
| 899 | + test("also accepts GraphQL AST DocumentNode", async () => { |
| 900 | + let result; |
| 901 | + |
| 902 | + const query = gql` |
| 903 | + query Status { |
| 904 | + status { |
| 905 | + backend |
| 906 | + smsGateway |
| 907 | + paypalIntegration |
| 908 | + } |
| 909 | + } |
| 910 | + `; |
| 911 | + |
| 912 | + const request = await recordGraphQLRequest(async () => { |
| 913 | + result = await store.dispatch("entities/simpleQuery", { query, variables: {} }); |
| 914 | + }); |
| 915 | + |
| 916 | + expect(result).toEqual({ |
| 917 | + status: { |
| 918 | + __typename: "Status", |
| 919 | + backend: true, |
| 920 | + paypalIntegration: true, |
| 921 | + smsGateway: false |
| 922 | + } |
| 923 | + }); |
| 924 | + |
| 925 | + expect(request!.query).toEqual( |
| 926 | + ` |
| 927 | +query Status { |
| 928 | + status { |
| 929 | + backend |
| 930 | + smsGateway |
| 931 | + paypalIntegration |
| 932 | + } |
858 | 933 | } |
859 | 934 | `.trim() + "\n" |
860 | 935 | ); |
|
0 commit comments