1- use crate :: {
2- executor:: Variables ,
3- schema:: model:: RootNode ,
4- types:: scalars:: { EmptyMutation , EmptySubscription } ,
5- value:: { DefaultScalarValue , Object , ParseScalarResult , ParseScalarValue , Value } ,
1+ use juniper:: {
2+ DefaultScalarValue , EmptyMutation , EmptySubscription , Object , ParseScalarResult ,
3+ ParseScalarValue , RootNode , Value , Variables ,
64} ;
75
86struct DefaultName ( i32 ) ;
@@ -21,66 +19,72 @@ Syntax to validate:
2119
2220*/
2321
24- graphql_scalar ! ( DefaultName where Scalar = <S > {
25- resolve( & self ) -> Value {
22+ #[ juniper:: graphql_scalar]
23+ impl < S > GraphQLScalar for DefaultName
24+ where
25+ S : juniper:: ScalarValue ,
26+ {
27+ fn resolve ( & self ) -> Value {
2628 Value :: scalar ( self . 0 )
2729 }
2830
29- from_input_value( v: & InputValue ) -> Option <DefaultName > {
30- v. as_scalar_value( ) . and_then( |s| s. as_int( ) ) . map( |i| DefaultName ( i) )
31+ fn from_input_value ( v : & juniper:: InputValue ) -> Option < DefaultName > {
32+ v. as_scalar_value ( )
33+ . and_then ( |s| s. as_int ( ) )
34+ . map ( |i| DefaultName ( i) )
3135 }
3236
33- from_str<' a>( value: ScalarToken <' a>) -> ParseScalarResult <' a, S > {
37+ fn from_str < ' a > ( value : juniper :: ScalarToken < ' a > ) -> ParseScalarResult < ' a , S > {
3438 <i32 as ParseScalarValue < S > >:: from_str ( value)
3539 }
36- } ) ;
40+ }
3741
38- graphql_scalar ! ( OtherOrder {
39- resolve( & self ) -> Value {
42+ #[ juniper:: graphql_scalar]
43+ impl GraphQLScalar for OtherOrder {
44+ fn resolve ( & self ) -> Value {
4045 Value :: scalar ( self . 0 )
4146 }
4247
43- from_input_value( v: & InputValue ) -> Option <OtherOrder > {
48+ fn from_input_value ( v : & juniper :: InputValue ) -> Option < OtherOrder > {
4449 v. as_scalar_value :: < i32 > ( ) . map ( |i| OtherOrder ( * i) )
4550 }
4651
47-
48- from_str<' a>( value: ScalarToken <' a>) -> ParseScalarResult <' a, DefaultScalarValue > {
52+ fn from_str < ' a > ( value : juniper:: ScalarToken < ' a > ) -> ParseScalarResult < ' a , DefaultScalarValue > {
4953 <i32 as ParseScalarValue >:: from_str ( value)
5054 }
51- } ) ;
55+ }
5256
53- graphql_scalar ! ( Named as "ANamedScalar" where Scalar = DefaultScalarValue {
54- resolve( & self ) -> Value {
57+ #[ juniper:: graphql_scalar( name = "ANamedScalar" ) ]
58+ impl GraphQLScalar for Named {
59+ fn resolve ( & self ) -> Value {
5560 Value :: scalar ( self . 0 )
5661 }
5762
58- from_input_value( v: & InputValue ) -> Option <Named > {
63+ fn from_input_value ( v : & juniper :: InputValue ) -> Option < Named > {
5964 v. as_scalar_value :: < i32 > ( ) . map ( |i| Named ( * i) )
6065 }
6166
62- from_str<' a>( value: ScalarToken <' a>) -> ParseScalarResult <' a, DefaultScalarValue > {
67+ fn from_str < ' a > ( value : juniper :: ScalarToken < ' a > ) -> ParseScalarResult < ' a , DefaultScalarValue > {
6368 <i32 as ParseScalarValue >:: from_str ( value)
6469 }
65- } ) ;
66-
67- graphql_scalar ! ( ScalarDescription {
68- description: "A sample scalar, represented as an integer"
70+ }
6971
70- resolve( & self ) -> Value {
72+ #[ juniper:: graphql_scalar( description = "A sample scalar, represented as an integer" ) ]
73+ impl GraphQLScalar for ScalarDescription {
74+ fn resolve ( & self ) -> Value {
7175 Value :: scalar ( self . 0 )
7276 }
7377
74- from_input_value( v: & InputValue ) -> Option <ScalarDescription > {
78+ fn from_input_value ( v : & juniper :: InputValue ) -> Option < ScalarDescription > {
7579 v. as_scalar_value :: < i32 > ( ) . map ( |i| ScalarDescription ( * i) )
7680 }
7781
78- from_str<' a>( value: ScalarToken <' a>) -> ParseScalarResult <' a> {
82+ fn from_str < ' a > ( value : juniper :: ScalarToken < ' a > ) -> ParseScalarResult < ' a , DefaultScalarValue > {
7983 <i32 as ParseScalarValue >:: from_str ( value)
8084 }
81- } ) ;
85+ }
8286
83- #[ crate :: graphql_object_internal ]
87+ #[ juniper :: graphql_object ]
8488impl Root {
8589 fn default_name ( ) -> DefaultName {
8690 DefaultName ( 0 )
@@ -106,7 +110,7 @@ where
106110 EmptySubscription :: < ( ) > :: new ( ) ,
107111 ) ;
108112
109- let ( result, errs) = crate :: execute ( doc, None , & schema, & Variables :: new ( ) , & ( ) )
113+ let ( result, errs) = juniper :: execute ( doc, None , & schema, & Variables :: new ( ) , & ( ) )
110114 . await
111115 . expect ( "Execution failed" ) ;
112116
@@ -129,19 +133,22 @@ where
129133fn path_in_resolve_return_type ( ) {
130134 struct ResolvePath ( i32 ) ;
131135
132- graphql_scalar ! ( ResolvePath {
133- resolve( & self ) -> self :: Value {
136+ #[ juniper:: graphql_scalar]
137+ impl GraphQLScalar for ResolvePath {
138+ fn resolve ( & self ) -> self :: Value {
134139 Value :: scalar ( self . 0 )
135140 }
136141
137- from_input_value( v: & InputValue ) -> Option <ResolvePath > {
142+ fn from_input_value ( v : & juniper :: InputValue ) -> Option < ResolvePath > {
138143 v. as_scalar_value :: < i32 > ( ) . map ( |i| ResolvePath ( * i) )
139144 }
140145
141- from_str<' a>( value: ScalarToken <' a>) -> ParseScalarResult <' a> {
146+ fn from_str < ' a > (
147+ value : juniper:: ScalarToken < ' a > ,
148+ ) -> ParseScalarResult < ' a , DefaultScalarValue > {
142149 <i32 as ParseScalarValue >:: from_str ( value)
143150 }
144- } ) ;
151+ }
145152}
146153
147154#[ tokio:: test]
0 commit comments