diff --git a/src/builder.rs b/src/builder.rs index 1b0140d0..0c1d4544 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -2475,6 +2475,7 @@ pub enum __TypeField { EnumValues(Option>), PossibleTypes(Option>), OfType(Option<__TypeBuilder>), + SpecifiedByURL, Typename { alias: String, typename: Option, @@ -2999,6 +3000,7 @@ impl __Schema { }; __TypeField::OfType(unwrapped_type_builder) } + "specifiedByURL" => __TypeField::SpecifiedByURL, introspection::TYPENAME => __TypeField::Typename { alias: alias_or_name(&selection_field), typename: type_.name(), diff --git a/src/graphql.rs b/src/graphql.rs index fb7b4339..b3fff41f 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -274,6 +274,12 @@ pub trait ___Type { fn of_type(&self) -> Option<__Type> { None } + + // # SCALAR only + // specifiedByURL: String + fn specified_by_url(&self) -> Option { + None + } } #[derive(Clone, Debug)] diff --git a/src/transpile.rs b/src/transpile.rs index 47c925e1..c2e79b1a 100644 --- a/src/transpile.rs +++ b/src/transpile.rs @@ -1900,6 +1900,9 @@ impl Serialize for __TypeBuilder { __TypeField::OfType(t_builder) => { map.serialize_entry(&selection.alias, t_builder)?; } + __TypeField::SpecifiedByURL => { + map.serialize_entry(&selection.alias, &self.type_.specified_by_url())?; + } __TypeField::Typename { alias, typename } => { map.serialize_entry(&alias, typename)?; } diff --git a/test/expected/resolve_specified_by_url.out b/test/expected/resolve_specified_by_url.out new file mode 100644 index 00000000..b9e986d5 --- /dev/null +++ b/test/expected/resolve_specified_by_url.out @@ -0,0 +1,30 @@ +begin; + comment on schema public is e'@graphql({"inflect_names": true, "introspection": true})'; + -- specifiedByURL should be queryable and return null for built-in scalars + select graphql.resolve( + query:='{ __type(name: "Boolean") { specifiedByURL } }' + ); + resolve +------------------------------------------------------------------ + {"data": {"__type": {"specifiedByURL": null}}} +(1 row) + + -- specifiedByURL should also work alongside other fields + select graphql.resolve( + query:='{ __type(name: "String") { name kind specifiedByURL } }' + ); + resolve +---------------------------------------------------------------------------------------------- + {"data": {"__type": {"kind": "SCALAR", "name": "String", "specifiedByURL": null}}} +(1 row) + + -- specifiedByURL on a non-scalar type (e.g. OBJECT) should also return null + select graphql.resolve( + query:='{ __type(name: "Query") { name kind specifiedByURL } }' + ); + resolve +--------------------------------------------------------------------------------------------- + {"data": {"__type": {"kind": "OBJECT", "name": "Query", "specifiedByURL": null}}} +(1 row) + +rollback; diff --git a/test/sql/resolve_specified_by_url.sql b/test/sql/resolve_specified_by_url.sql new file mode 100644 index 00000000..5392d2fb --- /dev/null +++ b/test/sql/resolve_specified_by_url.sql @@ -0,0 +1,19 @@ +begin; + comment on schema public is e'@graphql({"inflect_names": true, "introspection": true})'; + + -- specifiedByURL should be queryable and return null for built-in scalars + select graphql.resolve( + query:='{ __type(name: "Boolean") { specifiedByURL } }' + ); + + -- specifiedByURL should also work alongside other fields + select graphql.resolve( + query:='{ __type(name: "String") { name kind specifiedByURL } }' + ); + + -- specifiedByURL on a non-scalar type (e.g. OBJECT) should also return null + select graphql.resolve( + query:='{ __type(name: "Query") { name kind specifiedByURL } }' + ); + +rollback;