@@ -24,37 +24,6 @@ export const plugin: PluginFunction<
2424 ( d ) => d . kind === Kind . OPERATION_DEFINITION
2525 ) as OperationDefinitionNode [ ] ;
2626
27- const queryBuilder = (
28- queryName : string ,
29- operationType : OperationTypeNode ,
30- hasVariables : boolean ,
31- isNullSafety : boolean
32- ) => {
33- const operationStr = capitalizeFirstLetter ( operationType ) ;
34-
35- return `class ${ queryName } $${ operationStr } ReturnType {
36- bool isLoading;
37- OperationException${ isNullSafety ? '?' : '' } exception;
38- ${ queryName } $${ operationStr } ${ isNullSafety ? '?' : '' } data;
39-
40- ${ queryName } $${ operationStr } ReturnType(this.isLoading, this.exception, this.data);
41- }
42-
43- ${ queryName } $${ operationStr } ReturnType use${ queryName } Query<DataType>(BuildContext context${
44- hasVariables ? `, ${ queryName } Arguments variables` : ''
45- } ) {
46- final result = useQuery<${ queryName } $${ operationStr } >(context, ${ queryName
47- . match ( / [ A - Z ] [ a - z ] + / g)
48- . map ( ( s ) => s . toUpperCase ( ) )
49- . join ( '_' ) } _${ operationStr . toUpperCase ( ) } _DOCUMENT${
50- hasVariables ? `, variables.toJson()` : ''
51- } );
52- return ${ queryName } $${ operationStr } ReturnType(result.isLoading, result.exception, result.data == null ? null : ${ queryName } $${ operationStr } .fromJson(result.data${
53- isNullSafety ? '!' : ''
54- } ));
55- }` ;
56- } ;
57-
5827 return {
5928 content :
6029 packagesImportStr ( config . artemisImportPath ) +
@@ -68,10 +37,42 @@ ${queryName}$${operationStr}ReturnType use${queryName}Query<DataType>(BuildConte
6837 )
6938 ) . join ( `
7039
71- `) ,
40+ ` ) ,
7241 } ;
7342} ;
7443
44+ const queryBuilder = (
45+ queryName : string ,
46+ operationType : OperationTypeNode ,
47+ hasVariables : boolean ,
48+ isNullSafety : boolean
49+ ) => {
50+ const operationStr = capitalizeFirstLetter ( operationType ) ;
51+
52+ return `
53+ class ${ queryName } $${ operationStr } ReturnType {
54+ bool isLoading;
55+ OperationException${ isNullSafety ? '?' : '' } exception;
56+ ${ queryName } $${ operationStr } ${ isNullSafety ? '?' : '' } data;
57+
58+ ${ queryName } $${ operationStr } ReturnType(this.isLoading, this.exception, this.data);
59+ }
60+
61+ ${ queryName } $${ operationStr } ReturnType use${ queryName } Query<DataType>(BuildContext context${
62+ hasVariables ? `, ${ queryName } Arguments variables` : ''
63+ } ) {
64+ final result = useQuery<${ queryName } $${ operationStr } >(context, ${ queryName
65+ . match ( / [ A - Z ] [ a - z ] + / g)
66+ . map ( ( s ) => s . toUpperCase ( ) )
67+ . join ( '_' ) } _${ operationStr . toUpperCase ( ) } _DOCUMENT${
68+ hasVariables ? `, variables.toJson()` : ''
69+ } );
70+ return ${ queryName } $${ operationStr } ReturnType(result.isLoading, result.exception, result.data == null ? null : ${ queryName } $${ operationStr } .fromJson(result.data${
71+ isNullSafety ? '!' : ''
72+ } ));
73+ }` ;
74+ } ;
75+
7576function capitalizeFirstLetter ( string ) {
7677 return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
7778}
@@ -113,7 +114,9 @@ const useQueryString = (isNullSafety: boolean) =>
113114 return () {};
114115 }, []);
115116 return state.value;
116- }`
117+ }
118+
119+ `
117120 : `
118121QueryResult useQuery<DataType>(
119122 BuildContext context, DocumentNode query,
0 commit comments