Skip to content
Draft
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
30 changes: 21 additions & 9 deletions compiler/crates/relay-lsp/src/hover/with_resolution_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@
* LICENSE file in the root directory of this source tree.
*/

//! # Hover Tooltip Format
//!
//! Hover tooltips display information in this order:
//!
//! 1. Description: Human-readable description of the element (if available)
//!
//! 2. SDL Definition: GraphQL SDL syntax showing the element's signature
//! (e.g., `name(arg: String!): ID!` for fields, `type User { ... }` for types)
//!
//! 3. Type Link: Clickable link to the referenced type in the schema explorer,
//! with the type's description if available. Always shown for fields (even
//! without a type description). Omitted for built-in scalars
//! (`String`, `Int`, `Float`, `Boolean`, `ID`).
//!
//! 4. Documentation Links: Links to relevant documentation (e.g., Relay Resolver,
//! Client Schema Extension).
//!
//! 5. Source Links: Links to source code locations (e.g., Hack source).

use common::DirectiveName;
use common::NamedItem;
use docblock_shared::RELAY_RESOLVER_DIRECTIVE_NAME;
Expand Down Expand Up @@ -875,17 +894,10 @@ fn get_scalar_or_linked_field_hover_content(
}

if is_resolver {
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/).";
let msg = "**Relay Resolver**: [Learn More](https://relay.dev/docs/guides/relay-resolvers/introduction/)";
hover_contents.push(MarkedString::String(msg.to_string()))
} else if field.is_extension {
let msg = match content_consumer_type {
ContentConsumerType::Relay => {
"**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)."
}
ContentConsumerType::GraphQL => {
"**Client Schema Extension**: This field was declared as a GraphQL client schema extension explicitly among [these](https://fburl.com/code/9qg1gghd) files etc."
}
};
let msg = "**Client Schema Extension**: [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions)";
hover_contents.push(MarkedString::String(msg.to_string()))
}

Expand Down
16 changes: 16 additions & 0 deletions compiler/crates/relay-lsp/tests/hover/fixtures/directive.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
==================================== INPUT ====================================
query MyQuery {
node(id: "123") {
...MyFragment @de|fer(label: "test")
}
}

fragment MyFragment on Node {
id
}
==================================== OUTPUT ===================================
```graphql
directive @defer(label: String, if: Boolean = true) on FRAGMENT_SPREAD | INLINE_FRAGMENT


```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query MyQuery {
node(id: "123") {
...MyFragment @de|fer(label: "test")
}
}

fragment MyFragment on Node {
id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
==================================== INPUT ====================================
query MyQuery {
node(id: "123") {
... on User @ali|as(as: "myUser") {
name
}
}
}
==================================== OUTPUT ===================================
(Relay Only)

Exposes a fragment's data as a new field which can be null checked to ensure it
matches the parent selection.

[Read More](https://relay.dev/docs/guides/alias-directive/)
--
```graphql
directive @alias(as: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query MyQuery {
node(id: "123") {
... on User @ali|as(as: "myUser") {
name
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==================================== INPUT ====================================
query MyQuery {
me {
...MyFragment
}
}

fragment MyFragment on User @argumentDe|finitions(size: {type: "Int", defaultValue: 32}) {
profilePicture(size: [$size]) {
uri
}
}
==================================== OUTPUT ===================================

`@argumentDefinitions` is a directive used to specify arguments taken by a fragment.

---
@see: https://relay.dev/docs/api-reference/graphql-and-directives/#argumentdefinitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query MyQuery {
me {
...MyFragment
}
}

fragment MyFragment on User @argumentDe|finitions(size: {type: "Int", defaultValue: 32}) {
profilePicture(size: [$size]) {
uri
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==================================== INPUT ====================================
query MyQuery {
me {
...MyFragment @argu|ments(size: 10)
}
}

fragment MyFragment on User @argumentDefinitions(size: {type: "Int", defaultValue: 32}) {
profilePicture(size: [$size]) {
uri
}
}
==================================== OUTPUT ===================================

`@arguments` is a directive used to pass arguments to a fragment that was defined using `@argumentDefinitions`.

---
@see: https://relay.dev/docs/api-reference/graphql-and-directives/#arguments
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query MyQuery {
me {
...MyFragment @argu|ments(size: 10)
}
}

fragment MyFragment on User @argumentDefinitions(size: {type: "Int", defaultValue: 32}) {
profilePicture(size: [$size]) {
uri
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
==================================== INPUT ====================================
query MyQuery {
me {
name @requ|ired(action: THROW)
}
}
==================================== OUTPUT ===================================
(Relay Only)

`@required` is a directive you can add to fields in your Relay queries to
declare how null values should be handled at runtime. You can think of it as
saying "if this field is ever null, its parent field is invalid and should be
null".

[Read More](https://relay.dev/docs/guides/required-directive/)
--
```graphql
directive @required(action: RequiredFieldAction! @static) on FIELD
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery {
me {
name @requ|ired(action: THROW)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
==================================== INPUT ====================================
query MyQuery @throwOnFiel|dError {
me {
name
}
}
==================================== OUTPUT ===================================
(Relay only)

A directive added to queries and fragments which causes the Relay client to throw
if reading a field that has an error. Relay will also honor the @semanticNonNull
directive on fields read from that query or fragment. Emitted types for such
fields will be non-null. Requires the `experimental_emit_semantic_nullability_types`
typegen configuration to be enabled.

[Read More](https://relay.dev/docs/api-reference/graphql-and-directives/)
--
```graphql
directive @throwOnFieldError on QUERY | FRAGMENT_DEFINITION
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery @throwOnFiel|dError {
me {
name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Relay's cache key for this object.
--
Type: **[ID!](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22ID%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
--
**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).
**Client Schema Extension**: [Learn More](https://relay.dev/docs/guided-tour/updating-data/client-only-data/#client-only-data-client-schema-extensions)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
==================================== INPUT ====================================
query MyQuery {
node(i|d: "123") {
id
}
}
==================================== OUTPUT ===================================
Argument `id: "123"`
--
Field: **node**
--
Type: **[Node](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22Node%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
--
This field accepts these arguments
--
id: **[ID](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Node%22,%22ID%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery {
node(i|d: "123") {
id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
==================================== INPUT ====================================
query MyQuery {
me {
firstName(if: true|)
}
}
==================================== OUTPUT ===================================
Argument `if: true`
--
Field: **firstName**
--
Type: **[String](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22String%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
--
This field accepts these arguments
--
if: **[Boolean](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22String%22,%22Boolean%22],%22schemaName%22:%22Some%20Schema%20Name%22})**


--
unless: **[Boolean](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22String%22,%22Boolean%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery {
me {
firstName(if: true|)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
==================================== INPUT ====================================
query MyQuery {
me {
profilePicture(size: [32], preset: SMA|LL) {
uri
}
}
}
==================================== OUTPUT ===================================
Argument `preset: SMALL`
--
Field: **profilePicture**
--
Type: **[Image](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22Image%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
--
This field accepts these arguments
--
size: **[[Int]](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Image%22,%22Int%22],%22schemaName%22:%22Some%20Schema%20Name%22})**


--
preset: **[PhotoSize](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Image%22,%22PhotoSize%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query MyQuery {
me {
profilePicture(size: [32], preset: SMA|LL) {
uri
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
==================================== INPUT ====================================
query MyQuery {
me {
profile_picture(scale: 1.5|) {
uri
}
}
}
==================================== OUTPUT ===================================
Argument `scale: 1.5`
--
Field: **profile_picture**
--
Type: **[Image](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22Image%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
--
This field accepts these arguments
--
scale: **[Float](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Image%22,%22Float%22],%22schemaName%22:%22Some%20Schema%20Name%22})**


--
media_type: **[String](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Image%22,%22String%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query MyQuery {
me {
profile_picture(scale: 1.5|) {
uri
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
==================================== INPUT ====================================
query MyQuery($id: ID!) {
node(id: $i|d) {
id
}
}
==================================== OUTPUT ===================================
Argument `id: $id`
--
Field: **node**
--
Type: **[Node](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22Node%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
--
This field accepts these arguments
--
id: **[ID](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Node%22,%22ID%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery($id: ID!) {
node(id: $i|d) {
id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
==================================== INPUT ====================================
query MyQuery {
nod|e(id: "123") {
id
}
}
==================================== OUTPUT ===================================
Field: **node**
--
Type: **[Node](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22Node%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
--
This field accepts these arguments
--
id: **[ID](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Node%22,%22ID%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery {
nod|e(id: "123") {
id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==================================== INPUT ====================================
query MyQuery {
me {
...MyFragment
}
}

fragment MyFragment on Us|er {
name
}
==================================== OUTPUT ===================================
fragment MyFragment on [User](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22User%22],%22schemaName%22:%22Some%20Schema%20Name%22})
--
Fragments let you select fields,
and then include them in queries where you need to.

---
@see: https://graphql.org/learn/queries/#fragments
Loading
Loading