11use std:: collections:: BTreeMap ;
22
3- use graphql_parser:: { Pos , query , schema} ;
3+ use graphql_parser:: { Pos , schema} ;
44
55use crate :: {
66 ast,
@@ -127,15 +127,15 @@ impl GraphQLParserTranslator {
127127 }
128128 }
129129
130- fn translate_type < ' a , T > ( input : & ' a ast:: Type ) -> query :: Type < ' a , T >
130+ fn translate_type < ' a , T > ( input : & ' a ast:: Type ) -> schema :: Type < ' a , T >
131131 where
132132 T : schema:: Text < ' a > ,
133133 {
134- let mut ty = query :: Type :: NamedType ( input. innermost_name ( ) . into ( ) ) ;
134+ let mut ty = schema :: Type :: NamedType ( input. innermost_name ( ) . into ( ) ) ;
135135 for m in input. modifiers ( ) {
136136 ty = match m {
137- ast:: TypeModifier :: NonNull => query :: Type :: NonNullType ( ty. into ( ) ) ,
138- ast:: TypeModifier :: List ( ..) => query :: Type :: ListType ( ty. into ( ) ) ,
137+ ast:: TypeModifier :: NonNull => schema :: Type :: NonNullType ( ty. into ( ) ) ,
138+ ast:: TypeModifier :: List ( ..) => schema :: Type :: ListType ( ty. into ( ) ) ,
139139 } ;
140140 }
141141 ty
@@ -150,14 +150,17 @@ impl GraphQLParserTranslator {
150150 meta:: MetaType :: Scalar ( meta:: ScalarMeta {
151151 name,
152152 description,
153- specified_by_url : _ ,
153+ specified_by_url,
154154 try_parse_fn : _,
155155 parse_fn : _,
156156 } ) => schema:: TypeDefinition :: Scalar ( schema:: ScalarType {
157157 position : Pos :: default ( ) ,
158158 description : description. as_deref ( ) . map ( Into :: into) ,
159159 name : name. as_str ( ) . into ( ) ,
160- directives : vec ! [ ] , // TODO: show directive
160+ directives : specified_by_url
161+ . as_deref ( )
162+ . map ( |url| vec ! [ specified_by_url_to_directive( url) ] )
163+ . unwrap_or_default ( ) ,
161164 } ) ,
162165 meta:: MetaType :: Enum ( meta:: EnumMeta {
163166 name,
@@ -289,13 +292,13 @@ impl GraphQLParserTranslator {
289292
290293fn deprecation_to_directive < ' a , T > (
291294 status : & meta:: DeprecationStatus ,
292- ) -> Option < query :: Directive < ' a , T > >
295+ ) -> Option < schema :: Directive < ' a , T > >
293296where
294297 T : schema:: Text < ' a > ,
295298{
296299 match status {
297300 meta:: DeprecationStatus :: Current => None ,
298- meta:: DeprecationStatus :: Deprecated ( reason) => Some ( query :: Directive {
301+ meta:: DeprecationStatus :: Deprecated ( reason) => Some ( schema :: Directive {
299302 position : Pos :: default ( ) ,
300303 name : "deprecated" . into ( ) ,
301304 arguments : reason
@@ -306,10 +309,22 @@ where
306309 }
307310}
308311
312+ /// Returns the `@specifiedBy(url:)` [`schema::Directive`] for the provided `url`.
313+ fn specified_by_url_to_directive < ' a , T > ( url : & str ) -> schema:: Directive < ' a , T >
314+ where
315+ T : schema:: Text < ' a > ,
316+ {
317+ schema:: Directive {
318+ position : Pos :: default ( ) ,
319+ name : "specifiedBy" . into ( ) ,
320+ arguments : vec ! [ ( "url" . into( ) , schema:: Value :: String ( url. into( ) ) ) ] ,
321+ }
322+ }
323+
309324// Right now the only directive supported is `@deprecated`.
310325// `@skip` and `@include` are dealt with elsewhere.
311326// https://spec.graphql.org/October2021#sec-Type-System.Directives.Built-in-Directives
312- fn generate_directives < ' a , T > ( status : & meta:: DeprecationStatus ) -> Vec < query :: Directive < ' a , T > >
327+ fn generate_directives < ' a , T > ( status : & meta:: DeprecationStatus ) -> Vec < schema :: Directive < ' a , T > >
313328where
314329 T : schema:: Text < ' a > ,
315330{
0 commit comments