forked from facebook/relay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper functions on GraphQL schema Type implementation to check i…
…f it is a resolver type Summary: ## Context After this stack, we will have multiple files that need to identify legacy verbose resolver-defined models by checking that the `__relay_model_instance` field is missing. ## This diff This diff consolidates this logic into type checking methods on `Type` (along with `is_weak_resolver_object` / `is_resolver_object` checks). Also, refactored `client_edges.rs` to use the new helpers. Some tests were missing the `@__RelayResolverModel` annotations on the resolver objects, so I added them in. Reviewed By: captbaritone Differential Revision: D55155005 fbshipit-source-id: 1234699e08cae2c07fb30422eb04640c85b57f55
- Loading branch information
1 parent
2e62de4
commit e32755c
Showing
9 changed files
with
82 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 common::NamedItem; | ||
use docblock_shared::RELAY_RESOLVER_MODEL_DIRECTIVE_NAME; | ||
use docblock_shared::RELAY_RESOLVER_MODEL_INSTANCE_FIELD; | ||
use docblock_shared::RELAY_RESOLVER_WEAK_OBJECT_DIRECTIVE; | ||
use schema::Schema; | ||
use schema::Type; | ||
|
||
pub trait ResolverType { | ||
fn is_resolver_object<S: Schema>(&self, schema: &S) -> bool; | ||
fn is_weak_resolver_object<S: Schema>(&self, schema: &S) -> bool; | ||
fn is_terse_resolver_object<S: Schema>(&self, schema: &S) -> bool; | ||
} | ||
|
||
impl ResolverType for Type { | ||
fn is_resolver_object<S: Schema>(&self, schema: &S) -> bool { | ||
if let Type::Object(object_id) = self { | ||
let object = schema.object(*object_id); | ||
object | ||
.directives | ||
.named(*RELAY_RESOLVER_MODEL_DIRECTIVE_NAME) | ||
.is_some() | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
fn is_weak_resolver_object<S: Schema>(&self, schema: &S) -> bool { | ||
if let Type::Object(object_id) = self { | ||
let object = schema.object(*object_id); | ||
object | ||
.directives | ||
.named(*RELAY_RESOLVER_WEAK_OBJECT_DIRECTIVE) | ||
.is_some() | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
fn is_terse_resolver_object<S: Schema>(&self, schema: &S) -> bool { | ||
if let Type::Object(object_id) = self { | ||
let object = schema.object(*object_id); | ||
object.fields.iter().any(|field_id| { | ||
schema.field(*field_id).name.item == *RELAY_RESOLVER_MODEL_INSTANCE_FIELD | ||
}) | ||
} else { | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters