import { ApolloError } from "apollo-client" ; import { Vue } from "vue/types/vue" ; import { Prop } from "vue/types/options" ; import { VueApolloQueryDefinition } from "@vue/apollo-option/types/options" ; import { createDecorator , VueDecorator } from "vue-class-component" ; interface QueryOptions < C extends Vue , R = any > extends VueApolloQueryDefinition < R > { update ? : ( this : C , data : R ) => void ; skip ? : ( this : C ) => boolean ; result ? : ( this : C ) => void ; error ? : ( this : C , error : Error | ApolloError | string ) => void ; } interface QueryOptionsWithVariables < C extends Vue , R = any , V = undefined | null > extends QueryOptions < C , R > { variables : ( ( this : C ) => V ) | V ; } param options return export function Query < C extends Vue , R = any , V extends { } | null = null > ( options ) { return createDecorator ( ( componentOptions , key ) => { if ( ! componentOptions . apollo ) { componentOptions . apollo = { } ; } ; ( componentOptions . apollo as any ) [ key ] = { update : ( data ) => ( Object . keys ( data ) . includes ( key ) ? data [ key ] : data ) , ... options , } ; } ) ; } export function Required ( type ) { return createDecorator ( ( componentOptions , key ) => { if ( ! componentOptions . props ) { componentOptions . props = { } ; } ; ( componentOptions . props as any ) [ key ] = { type , required : true , } ; } ) ; } type Constructor = NumberConstructor | StringConstructor | ArrayConstructor | BooleanConstructor ; export function Default < T extends Constructor | ObjectConstructor > ( type , defaultValue ) { return createDecorator ( ( componentOptions , key ) => { if ( ! componentOptions . props ) { componentOptions . props = { } ; } ; ( componentOptions . props as any ) [ key ] = { type , required : false , default : defaultValue , } ; if ( Array . isArray ( defaultValue ) || typeof defaultValue === "object" ) { ; ( componentOptions . props as any ) [ key ] . default = ( ) => defaultValue ; } } ) ; }