|
| 1 | +// PublishPartialSchemaMutation |
| 2 | +use crate::blocking::StudioClient; |
| 3 | +use crate::RoverClientError; |
| 4 | +use graphql_client::*; |
| 5 | + |
| 6 | +#[derive(GraphQLQuery)] |
| 7 | +// The paths are relative to the directory where your `Cargo.toml` is located. |
| 8 | +// Both json and the GraphQL schema language are supported as sources for the schema |
| 9 | +#[graphql( |
| 10 | + query_path = "src/query/config/is_federated.graphql", |
| 11 | + schema_path = ".schema/schema.graphql", |
| 12 | + response_derives = "PartialEq, Debug, Serialize, Deserialize", |
| 13 | + deprecated = "warn" |
| 14 | +)] |
| 15 | +/// This struct is used to generate the module containing `Variables` and |
| 16 | +/// `ResponseData` structs. |
| 17 | +/// Snake case of this name is the mod name. i.e. publish_partial_schema_mutation |
| 18 | +pub struct IsFederatedGraph; |
| 19 | + |
| 20 | +#[derive(Debug, PartialEq)] |
| 21 | +pub struct IsFederatedGraphResponse { |
| 22 | + pub result: bool, |
| 23 | +} |
| 24 | + |
| 25 | +pub fn run( |
| 26 | + variables: is_federated_graph::Variables, |
| 27 | + client: &StudioClient, |
| 28 | +) -> Result<IsFederatedGraphResponse, RoverClientError> { |
| 29 | + let data = client.post::<IsFederatedGraph>(variables)?; |
| 30 | + let is_federated_response = data.service.unwrap(); |
| 31 | + Ok(build_response(is_federated_response)) |
| 32 | +} |
| 33 | + |
| 34 | +type FederatedResponse = is_federated_graph::IsFederatedGraphService; |
| 35 | +type ImplementingServices = is_federated_graph::IsFederatedGraphServiceImplementingServices; |
| 36 | + |
| 37 | +fn build_response(service: FederatedResponse) -> IsFederatedGraphResponse { |
| 38 | + match service.implementing_services { |
| 39 | + Some(typename) => match typename { |
| 40 | + ImplementingServices::FederatedImplementingServices => { |
| 41 | + IsFederatedGraphResponse { result: true } |
| 42 | + } |
| 43 | + ImplementingServices::NonFederatedImplementingService => { |
| 44 | + IsFederatedGraphResponse { result: false } |
| 45 | + } |
| 46 | + }, |
| 47 | + None => IsFederatedGraphResponse { result: false }, |
| 48 | + } |
| 49 | +} |
0 commit comments