Skip to content

Commit 6db59f5

Browse files
committed
Add builtin scalar helpers and improve hover tooltip infrastructure
- Add BUILTIN_SCALAR_NAMES constant and is_builtin_scalar_name() function to schema crate for consistent builtin scalar handling - Update schema-set to use BUILTIN_SCALAR_NAMES instead of hardcoded list - Add TruncatedPrinter with print_field() and print_type_truncated() functions to schema-print crate for hover tooltip SDL generation - Add "..." truncation indicator when type definitions are truncated - Add module docblock documenting hover tooltip format conventions - Simplify Client Schema Extension hover message to always show Relay docs link
1 parent 1218175 commit 6db59f5

15 files changed

Lines changed: 332 additions & 20 deletions

compiler/crates/relay-lsp/src/hover/with_resolution_path.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
//! # Hover Tooltip Format
9+
//!
10+
//! Hover tooltips display information in this order:
11+
//!
12+
//! 1. Description: Human-readable description of the element (if available)
13+
//!
14+
//! 2. SDL Definition: GraphQL SDL syntax showing the element's signature
15+
//! (e.g., `name(arg: String!): ID!` for fields, `type User { ... }` for types)
16+
//!
17+
//! 3. Type Link: Clickable link to the referenced type in the schema explorer,
18+
//! with the type's description if available. Always shown for fields (even
19+
//! without a type description). Omitted for built-in scalars
20+
//! (`String`, `Int`, `Float`, `Boolean`, `ID`).
21+
//!
22+
//! 4. Documentation Links: Links to relevant documentation (e.g., Relay Resolver,
23+
//! Client Schema Extension).
24+
//!
25+
//! 5. Source Links: Links to source code locations (e.g., Hack source).
26+
827
use common::DirectiveName;
928
use common::NamedItem;
1029
use docblock_shared::RELAY_RESOLVER_DIRECTIVE_NAME;
@@ -875,17 +894,10 @@ fn get_scalar_or_linked_field_hover_content(
875894
}
876895

877896
if is_resolver {
878-
let msg = "**Relay Resolver**: This field is backed by a Relay Resolver, and is therefore only avaliable in Relay code. [Learn More](https://relay.dev/docs/guides/relay-resolvers/introduction/).";
897+
let msg = "**Relay Resolver**: [Learn More](https://relay.dev/docs/guides/relay-resolvers/introduction/)";
879898
hover_contents.push(MarkedString::String(msg.to_string()))
880899
} else if field.is_extension {
881-
let msg = match content_consumer_type {
882-
ContentConsumerType::Relay => {
883-
"**Client Schema Extension**: This field was declared as a Relay Client Schema Extension, and is therefore only avalaible in Relay code. [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions)."
884-
}
885-
ContentConsumerType::GraphQL => {
886-
"**Client Schema Extension**: This field was declared as a GraphQL client schema extension explicitly among [these](https://fburl.com/code/9qg1gghd) files etc."
887-
}
888-
};
900+
let msg = "**Client Schema Extension**: [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions)";
889901
hover_contents.push(MarkedString::String(msg.to_string()))
890902
}
891903

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
==================================== INPUT ====================================
2+
query MyQuery {
3+
node(id: "123") {
4+
... on User @ali|as(as: "myUser") {
5+
name
6+
}
7+
}
8+
}
9+
==================================== OUTPUT ===================================
10+
(Relay Only)
11+
12+
Exposes a fragment's data as a new field which can be null checked to ensure it
13+
matches the parent selection.
14+
15+
[Read More](https://relay.dev/docs/guides/alias-directive/)
16+
--
17+
```graphql
18+
directive @alias(as: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT
19+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
query MyQuery {
2+
node(id: "123") {
3+
... on User @ali|as(as: "myUser") {
4+
name
5+
}
6+
}
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
==================================== INPUT ====================================
2+
query MyQuery {
3+
me {
4+
name @requ|ired(action: THROW)
5+
}
6+
}
7+
==================================== OUTPUT ===================================
8+
(Relay Only)
9+
10+
`@required` is a directive you can add to fields in your Relay queries to
11+
declare how null values should be handled at runtime. You can think of it as
12+
saying "if this field is ever null, its parent field is invalid and should be
13+
null".
14+
15+
[Read More](https://relay.dev/docs/guides/required-directive/)
16+
--
17+
```graphql
18+
directive @required(action: RequiredFieldAction! @static) on FIELD
19+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query MyQuery {
2+
me {
3+
name @requ|ired(action: THROW)
4+
}
5+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
==================================== INPUT ====================================
2+
query MyQuery @throwOnFiel|dError {
3+
me {
4+
name
5+
}
6+
}
7+
==================================== OUTPUT ===================================
8+
(Relay only)
9+
10+
A directive added to queries and fragments which causes the Relay client to throw
11+
if reading a field that has an error. Relay will also honor the @semanticNonNull
12+
directive on fields read from that query or fragment. Emitted types for such
13+
fields will be non-null. Requires the `experimental_emit_semantic_nullability_types`
14+
typegen configuration to be enabled.
15+
16+
[Read More](https://relay.dev/docs/api-reference/graphql-and-directives/)
17+
--
18+
```graphql
19+
directive @throwOnFieldError on QUERY | FRAGMENT_DEFINITION
20+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query MyQuery @throwOnFiel|dError {
2+
me {
3+
name
4+
}
5+
}

compiler/crates/relay-lsp/tests/hover/fixtures/double_underscore_id_field.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Relay's cache key for this object.
1111
--
1212
Type: **[ID!](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22ID%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
1313
--
14-
**Client Schema Extension**: This field was declared as a Relay Client Schema Extension, and is therefore only avalaible in Relay code. [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions).
14+
**Client Schema Extension**: [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions)

compiler/crates/relay-lsp/tests/hover/fixtures/scalar_field_from_client_schema_extension.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ This is a client schema field
2020
--
2121
Type: **[Int](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22Int%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
2222
--
23-
**Client Schema Extension**: This field was declared as a Relay Client Schema Extension, and is therefore only avalaible in Relay code. [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions).
23+
**Client Schema Extension**: [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions)

compiler/crates/relay-lsp/tests/hover/fixtures/scalar_field_from_relay_resolver.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ My Resolver Description
2121
--
2222
Type: **[RelayResolverValue](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22RelayResolverValue%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
2323
--
24-
**Relay Resolver**: This field is backed by a Relay Resolver, and is therefore only avaliable in Relay code. [Learn More](https://relay.dev/docs/guides/relay-resolvers/introduction/).
24+
**Relay Resolver**: [Learn More](https://relay.dev/docs/guides/relay-resolvers/introduction/)

0 commit comments

Comments
 (0)