Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,7 @@ pub enum __TypeField {
EnumValues(Option<Vec<__EnumValueBuilder>>),
PossibleTypes(Option<Vec<__TypeBuilder>>),
OfType(Option<__TypeBuilder>),
SpecifiedByURL,
Typename {
alias: String,
typename: Option<String>,
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ pub trait ___Type {
fn of_type(&self) -> Option<__Type> {
None
}

// # SCALAR only
// specifiedByURL: String
fn specified_by_url(&self) -> Option<String> {
None
}
}

#[derive(Clone, Debug)]
Expand Down
3 changes: 3 additions & 0 deletions src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
30 changes: 30 additions & 0 deletions test/expected/resolve_specified_by_url.out
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions test/sql/resolve_specified_by_url.sql
Original file line number Diff line number Diff line change
@@ -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;
Loading