Skip to content

Commit

Permalink
Document __typename and __id in LSP hover
Browse files Browse the repository at this point in the history
Reviewed By: alunyov

Differential Revision: D39375625

fbshipit-source-id: e6266ac1b0305eae885ac488bd452e135f82a800
  • Loading branch information
captbaritone authored and facebook-github-bot committed Sep 9, 2022
1 parent d24c295 commit 298af34
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
==================================== INPUT ====================================
query MyQuery {
me {
_|_id
}
}
==================================== OUTPUT ===================================
Field: **__id**
--
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).
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery {
me {
_|_id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
==================================== INPUT ====================================
query MyQuery {
me {
_|_typename
}
}
==================================== OUTPUT ===================================
Field: **__typename**
--
This object's GraphQL type. Provided by GraphQL type name introspection.
--
Type: **[String!](command:nuclide.relay-lsp.openSchemaExplorer?{%22path%22:[%22Query%22,%22User%22,%22String%22],%22schemaName%22:%22Some%20Schema%20Name%22})**
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query MyQuery {
me {
_|_typename
}
}
16 changes: 15 additions & 1 deletion compiler/crates/relay-lsp/tests/hover_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<6daa50c6d4e1f509314b7c28a29bf686>>
* @generated SignedSource<<7e6c48eb62c1d815fb6644cb2e6e3bb3>>
*/

mod hover;

use hover::transform_fixture;
use fixture_tests::test_fixture;

#[test]
fn double_underscore_id_field() {
let input = include_str!("hover/fixtures/double_underscore_id_field.graphql");
let expected = include_str!("hover/fixtures/double_underscore_id_field.expected");
test_fixture(transform_fixture, "double_underscore_id_field.graphql", "hover/fixtures/double_underscore_id_field.expected", input, expected);
}

#[test]
fn double_underscore_typename_field() {
let input = include_str!("hover/fixtures/double_underscore_typename_field.graphql");
let expected = include_str!("hover/fixtures/double_underscore_typename_field.expected");
test_fixture(transform_fixture, "double_underscore_typename_field.graphql", "hover/fixtures/double_underscore_typename_field.expected", input, expected);
}

#[test]
fn fragment_definition_name() {
let input = include_str!("hover/fixtures/fragment_definition_name.graphql");
Expand Down
16 changes: 16 additions & 0 deletions compiler/crates/schema/src/field_descriptions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

use intern::string_key::Intern;
use intern::string_key::StringKey;
use lazy_static::lazy_static;

lazy_static! {
pub static ref CLIENT_ID_DESCRIPTION: StringKey = "Relay's cache key for this object.".intern();
pub static ref TYPENAME_DESCRIPTION: StringKey =
"This object's GraphQL type. Provided by GraphQL type name introspection.".intern();
}
26 changes: 15 additions & 11 deletions compiler/crates/schema/src/flatbuffer/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use intern::string_key::StringKey;
use ouroboros::self_referencing;

use super::FlatBufferSchema;
use crate::field_descriptions::CLIENT_ID_DESCRIPTION;
use crate::field_descriptions::TYPENAME_DESCRIPTION;
use crate::Argument;
use crate::ArgumentDefinitions;
use crate::Directive;
Expand Down Expand Up @@ -122,16 +124,18 @@ impl SchemaWrapper {
parent_type: None,
description: None,
});
result.fields.get(CLIENTID_FIELD_ID, || Field {
name: WithLocation::generated(result.clientid_field_name),
is_extension: true,
arguments: ArgumentDefinitions::new(Default::default()),
type_: TypeReference::NonNull(Box::new(TypeReference::Named(
result.get_type("ID".intern()).unwrap(),
))),
directives: Vec::new(),
parent_type: None,
description: None,
result.fields.get(CLIENTID_FIELD_ID, || -> Field {
Field {
name: WithLocation::generated(result.clientid_field_name),
is_extension: true,
arguments: ArgumentDefinitions::new(Default::default()),
type_: TypeReference::NonNull(Box::new(TypeReference::Named(
result.get_type("ID".intern()).unwrap(),
))),
directives: Vec::new(),
parent_type: None,
description: Some(*CLIENT_ID_DESCRIPTION),
}
});
result.fields.get(STRONGID_FIELD_ID, || Field {
name: WithLocation::generated(result.strongid_field_name),
Expand All @@ -140,7 +144,7 @@ impl SchemaWrapper {
type_: TypeReference::Named(result.get_type("ID".intern()).unwrap()),
directives: Vec::new(),
parent_type: None,
description: None,
description: Some(*TYPENAME_DESCRIPTION),
});
result.fields.get(FETCH_TOKEN_FIELD_ID, || Field {
name: WithLocation::generated(result.fetch_token_field_name),
Expand Down
6 changes: 4 additions & 2 deletions compiler/crates/schema/src/in_memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::definitions::Argument;
use crate::definitions::Directive;
use crate::definitions::*;
use crate::errors::SchemaError;
use crate::field_descriptions::CLIENT_ID_DESCRIPTION;
use crate::field_descriptions::TYPENAME_DESCRIPTION;
use crate::graphql_schema::Schema;

fn todo_add_location<T>(error: SchemaError) -> DiagnosticsResult<T> {
Expand Down Expand Up @@ -906,7 +908,7 @@ impl InMemorySchema {
type_: TypeReference::NonNull(Box::new(TypeReference::Named(string_type))),
directives: Vec::new(),
parent_type: None,
description: None,
description: Some(*TYPENAME_DESCRIPTION),
});
}

Expand Down Expand Up @@ -936,7 +938,7 @@ impl InMemorySchema {
type_: TypeReference::NonNull(Box::new(TypeReference::Named(id_type))),
directives: Vec::new(),
parent_type: None,
description: None,
description: Some(*CLIENT_ID_DESCRIPTION),
});
}

Expand Down
1 change: 1 addition & 0 deletions compiler/crates/schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

pub mod definitions;
mod errors;
mod field_descriptions;
mod flatbuffer;
mod graphql_schema;
mod in_memory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"This object's GraphQL type. Provided by GraphQL type name introspection.",
),
},
Field {
name: WithLocation {
Expand Down Expand Up @@ -219,7 +221,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"Relay's cache key for this object.",
),
},
Field {
name: WithLocation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"This object's GraphQL type. Provided by GraphQL type name introspection.",
),
},
Field {
name: WithLocation {
Expand Down Expand Up @@ -544,7 +546,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"Relay's cache key for this object.",
),
},
Field {
name: WithLocation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"This object's GraphQL type. Provided by GraphQL type name introspection.",
),
},
Field {
name: WithLocation {
Expand Down Expand Up @@ -280,7 +282,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"Relay's cache key for this object.",
),
},
Field {
name: WithLocation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"This object's GraphQL type. Provided by GraphQL type name introspection.",
),
},
Field {
name: WithLocation {
Expand Down Expand Up @@ -305,7 +307,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"Relay's cache key for this object.",
),
},
Field {
name: WithLocation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"This object's GraphQL type. Provided by GraphQL type name introspection.",
),
},
Field {
name: WithLocation {
Expand Down Expand Up @@ -478,7 +480,9 @@ Text Schema:Schema {
),
directives: [],
parent_type: None,
description: None,
description: Some(
"Relay's cache key for this object.",
),
},
Field {
name: WithLocation {
Expand Down

0 comments on commit 298af34

Please sign in to comment.