Skip to content

Commit 9f165c6

Browse files
committed
Fix missing @specifiedBy(url:) in SDL
1 parent 52fc466 commit 9f165c6

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

juniper/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
3737
### Fixed
3838

3939
- Incorrect `__Type.specifiedByUrl` field to `__Type.specifiedByURL`. ([#1348])
40+
- Missing `@specifiedBy(url:)` directive in [SDL] generated by `RootNode::as_sdl()` and `RootNode::as_document()` methods. ([#1348])
4041

4142
[#1347]: /../../issues/1347
4243
[#1348]: /../../pull/1348
@@ -442,3 +443,4 @@ See [old CHANGELOG](/../../blob/juniper-v0.15.12/juniper/CHANGELOG.md).
442443
[orphan rules]: https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
443444
[Semantic Versioning 2.0.0]: https://semver.org
444445
[September 2025]: https://spec.graphql.org/September2025
446+
[SDL]: https://graphql.org/learn/schema#type-language

juniper/src/schema/model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ where
194194
///
195195
/// # Unsorted
196196
///
197-
/// The order of the generated definitions in the returned [`Document`] is NOT stable and may change without any
198-
/// real schema changes.
197+
/// The order of the generated definitions in the returned [`Document`] is NOT stable and may
198+
/// change without any real schema changes.
199199
#[must_use]
200200
pub fn as_document(&self) -> Document<'_, &str> {
201201
use crate::schema::translate::{

juniper/src/schema/translate/graphql_parser.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::BTreeMap;
22

3-
use graphql_parser::{Pos, query, schema};
3+
use graphql_parser::{Pos, schema};
44

55
use 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

290293
fn deprecation_to_directive<'a, T>(
291294
status: &meta::DeprecationStatus,
292-
) -> Option<query::Directive<'a, T>>
295+
) -> Option<schema::Directive<'a, T>>
293296
where
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>>
313328
where
314329
T: schema::Text<'a>,
315330
{

0 commit comments

Comments
 (0)