Skip to content

Commit

Permalink
emit identifier info in dedicated object
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilios1995 committed Mar 20, 2023
1 parent c5be931 commit c3866a7
Show file tree
Hide file tree
Showing 107 changed files with 763 additions and 388 deletions.
16 changes: 6 additions & 10 deletions compiler/crates/relay-codegen/src/build_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,13 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> {
),
operation: Primitive::GraphQLModuleDependency(GraphQLModuleDependency::Name(refetch_metadata.operation_name.into())),
};
if let Some(identifier_field) = refetch_metadata.identifier_field {
if let Some(identifier_info) = &refetch_metadata.identifier_info {
refetch_object.push(ObjectEntry {
key: CODEGEN_CONSTANTS.identifier_field,
value: Primitive::String(identifier_field),
});
}

if let Some(x) = refetch_metadata.identifier_query_variable_name {
refetch_object.push(ObjectEntry {
key: CODEGEN_CONSTANTS.identifier_query_variable_name,
value: Primitive::String(x),
key: CODEGEN_CONSTANTS.identifier_info,
value: Primitive::Key(self.object(object! {
identifier_field: Primitive::String(identifier_info.identifier_field),
identifier_query_variable_name: Primitive::String(identifier_info.identifier_query_variable_name),
})),
});
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/crates/relay-codegen/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct CodegenConstants {
pub id: StringKey,
pub identifier_field: StringKey,
pub identifier_query_variable_name: StringKey,
pub identifier_info: StringKey,
pub if_: StringKey,
pub inline_data_fragment_spread: StringKey,
pub inline_data_fragment: StringKey,
Expand Down Expand Up @@ -172,6 +173,7 @@ lazy_static! {
id: "id".intern(),
identifier_field: "identifierField".intern(),
identifier_query_variable_name: "identifierQueryVariableName".intern(),
identifier_info: "identifierInfo".intern(),
if_: "if".intern(),
inline_data_fragment_spread: "InlineDataFragmentSpread".intern(),
inline_data_fragment: "InlineDataFragment".intern(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ extend type User {
"node"
],
"operation": require('ClientEdgeQuery_Foo_user_best_friend.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "RefetchableClientEdgeQuery_Foo_user_best_friend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ fragment fragmentOnNodeInterface_RefetchableFragment on Node {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "fragmentOnNodeInterface_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ fragment fragmentOnNonNodeFetchableType_RefetchableFragment on NonNodeStory {
"fetch__NonNodeStory"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "fetch_id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "fetch_id",
"identifierQueryVariableName": "id"
}
}
},
"name": "fragmentOnNonNodeFetchableType_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ fragment fragmentOnObjectImplementingNodeInterface_RefetchableFragment on User {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "fragmentOnObjectImplementingNodeInterface_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,10 @@ fragment providedVariableRefetchableFragment_providedVariableFragment on User {
"node"
],
"operation": require('refetchableQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "providedVariableRefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ fragment refetchableConnectionCustomHandler_RefetchableConnection_feedback on Fe
"node"
],
"operation": require('RefetchableConnectionQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableConnectionCustomHandler_RefetchableConnection_feedback",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ fragment refetchableConnection_RefetchableConnection_feedback on Feedback {
"node"
],
"operation": require('RefetchableConnectionQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableConnection_RefetchableConnection_feedback",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ fragment refetchableFragmentOnNodeWithMissingId_RefetchableFragment on Node {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableFragmentOnNodeWithMissingId_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,10 @@ fragment refetchableFragmentWithConnectionBidirectional_PaginationFragment_1G22u
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableFragmentWithConnectionBidirectional_PaginationFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ import RefetchableFragmentQuery_graphql from './RefetchableFragmentQuery.graphql
"node"
],
"operation": RefetchableFragmentQuery_graphql,
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableFragmentWithConnectionEsModules_PaginationFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,10 @@ fragment refetchableFragmentWithConnectionWithStream_PaginationFragment_1G22uz o
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableFragmentWithConnectionWithStream_PaginationFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ fragment refetchableFragmentWithConnection_PaginationFragment_1G22uz on Node {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableFragmentWithConnection_PaginationFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ fragment relayResolverBackingClientEdge_best_friend_resolver on User {
"node"
],
"operation": require('ClientEdgeQuery_relayResolverBackingClientEdgeQuery_me__best_friend.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "RefetchableClientEdgeQuery_relayResolverBackingClientEdgeQuery_me__best_friend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,10 @@ fragment relayResolverWithRequiredClientEdge_best_friend_resolver on User {
"node"
],
"operation": require('ClientEdgeQuery_relayResolverWithRequiredClientEdgeQuery_me__best_friend.graphql'),
"identifierField": "id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "id",
"identifierQueryVariableName": "id"
}
}
},
"name": "RefetchableClientEdgeQuery_relayResolverWithRequiredClientEdgeQuery_me__best_friend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ fragment fragmentOnNodeInterface_RefetchableFragment on Node {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "global_id",
"identifierQueryVariableName": "variable_name"
"indentifierInfo": {
"identifierField": "global_id",
"identifierQueryVariableName": "variable_name"
}
}
},
"name": "fragmentOnNodeInterface_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ fragment fragmentOnNodeInterface_RefetchableFragment on Node {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "global_id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "global_id",
"identifierQueryVariableName": "id"
}
}
},
"name": "fragmentOnNodeInterface_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ fragment fragmentOnObjectImplementingNodeInterface_RefetchableFragment on User {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "global_id",
"identifierQueryVariableName": "variable_name"
"indentifierInfo": {
"identifierField": "global_id",
"identifierQueryVariableName": "variable_name"
}
}
},
"name": "fragmentOnObjectImplementingNodeInterface_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ fragment fragmentOnObjectImplementingNodeInterface_RefetchableFragment on User {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "global_id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "global_id",
"identifierQueryVariableName": "id"
}
}
},
"name": "fragmentOnObjectImplementingNodeInterface_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ fragment refetchableConnection_RefetchableConnection_feedback on Feedback {
"node"
],
"operation": require('RefetchableConnectionQuery.graphql'),
"identifierField": "global_id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "global_id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableConnection_RefetchableConnection_feedback",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ fragment refetchableConnection_RefetchableConnection_feedback on Feedback {
"node"
],
"operation": require('RefetchableConnectionQuery.graphql'),
"identifierField": "global_id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "global_id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableConnection_RefetchableConnection_feedback",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ fragment refetchableFragmentOnNodeWithMissingId_RefetchableFragment on Node {
"node"
],
"operation": require('RefetchableFragmentQuery.graphql'),
"identifierField": "global_id",
"identifierQueryVariableName": "id"
"indentifierInfo": {
"identifierField": "global_id",
"identifierQueryVariableName": "id"
}
}
},
"name": "refetchableFragmentOnNodeWithMissingId_RefetchableFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use super::build_used_global_variables;
use super::validation_message::ValidationMessage;
use super::QueryGenerator;
use super::RefetchRoot;
use super::RefetchableIdentifierInfo;
use super::RefetchableMetadata;
use super::CONSTANTS;
use crate::root_variables::VariableMap;
Expand Down Expand Up @@ -72,8 +73,11 @@ fn build_refetch_operation(
RefetchableMetadata {
operation_name: query_name,
path: vec![fetch_field_name],
identifier_field: Some(identifier_field_name),
identifier_query_variable_name: Some(schema_config.node_interface_id_variable_name),
identifier_info: Some(RefetchableIdentifierInfo {
identifier_field: identifier_field_name,
identifier_query_variable_name: schema_config
.node_interface_id_variable_name,
}),
},
),
selections: enforce_selections_with_id_field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use super::validation_message::ValidationMessage;
use super::QueryGenerator;
use super::RefetchRoot;
use super::RefetchableMetadata;
use super::RefetchableIdentifierInfo;
use super::CONSTANTS;
use crate::root_variables::VariableMap;

Expand Down Expand Up @@ -120,8 +121,11 @@ fn build_refetch_operation(
RefetchableMetadata {
operation_name: query_name,
path: vec![CONSTANTS.node_field_name],
identifier_field: Some(id_name),
identifier_query_variable_name: Some(schema_config.node_interface_id_variable_name),
identifier_info: Some(RefetchableIdentifierInfo {
identifier_field: id_name,
identifier_query_variable_name: schema_config
.node_interface_id_variable_name,
}),
},
),
used_global_variables: build_used_global_variables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ fn build_refetch_operation(
RefetchableMetadata {
operation_name: query_name,
path: vec![],
identifier_field: None,
identifier_query_variable_name: None,
identifier_info: None,
},
),
used_global_variables: build_used_global_variables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ use lazy_static::lazy_static;
use super::validation_message::ValidationMessage;
use crate::root_variables::VariableMap;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RefetchableIdentifierInfo {
pub identifier_field: StringKey,
pub identifier_query_variable_name: StringKey,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RefetchableMetadata {
pub operation_name: OperationDefinitionName,
pub path: Vec<StringKey>,
pub identifier_field: Option<StringKey>,
pub identifier_query_variable_name: Option<StringKey>,
pub identifier_info: Option<RefetchableIdentifierInfo>,
}
associated_data_impl!(RefetchableMetadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ fn build_refetch_operation(
RefetchableMetadata {
operation_name: query_name,
path: vec![CONSTANTS.viewer_field_name],
identifier_field: None,
identifier_query_variable_name: None,
identifier_info: None,
},
),
used_global_variables: build_used_global_variables(
Expand Down
Loading

0 comments on commit c3866a7

Please sign in to comment.