Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
collapse all modules into single crate (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszkuc authored Oct 19, 2023
1 parent d9fffb4 commit 69eccda
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 123 deletions.
10 changes: 2 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
[workspace]

members = [
"apollo-at-link",
"apollo-federation-error",
"apollo-federation",
"apollo-harness",
"apollo-subgraph",
"apollo-supergraph",
]

default-members = [
"apollo-at-link",
"apollo-federation-error",
"apollo-subgraph",
"apollo-supergraph",
"apollo-federation",
]

resolver = "2"
3 changes: 0 additions & 3 deletions apollo-at-link/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions apollo-at-link/src/lib.rs

This file was deleted.

14 changes: 0 additions & 14 deletions apollo-federation-error/Cargo.toml

This file was deleted.

2 changes: 0 additions & 2 deletions apollo-federation-error/src/lib.rs

This file was deleted.

10 changes: 7 additions & 3 deletions apollo-at-link/Cargo.toml → apollo-federation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "apollo-at-link"
name = "apollo-federation"
version = "0.0.1"
authors = ["The Apollo GraphQL Contributors"]
edition = "2021"
description = "Apollo Federation @link usage"
documentation = "https://docs.rs/apollo-at-link"
description = "Apollo Federation"
documentation = "https://docs.rs/apollo-federation"
repository = "https://github.com/apollographql/federation-next"
license = "Elastic-2.0"

Expand All @@ -13,8 +13,12 @@ license = "Elastic-2.0"
[dependencies]
apollo-compiler = "=1.0.0-beta.4"
salsa = "0.16.1"
indexmap = "2.0.0"
thiserror = "1.0"
url = "2"
lazy_static = "1.4.0"
strum = "0.25.0"
strum_macros = "0.25.2"

[dev-dependencies]
env_logger = "0.7"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{Supergraph, SupergraphError};
use apollo_at_link::{
use std::sync::Arc;

use apollo_compiler::Schema;

use crate::link::{
database::links_metadata,
link::Link,
spec::{Identity, APOLLO_SPEC_DOMAIN},
Link,
};
use apollo_compiler::Schema;
use apollo_subgraph::Subgraphs;
use std::sync::Arc;
use crate::subgraph::Subgraphs;
use crate::{Supergraph, SupergraphError};

// TODO: we should define this as part as some more generic "JoinSpec" definition, but need
// to define the ground work for that in `apollo-at-link` first.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::ast::AstNode;
use std::fmt::{Display, Formatter, Write};

use indexmap::IndexMap;
use lazy_static::lazy_static;
use std::fmt::{Display, Formatter, Write};
use strum::IntoEnumIterator;

use crate::error::ast::AstNode;

pub mod ast;

// What we really needed here was the string representations in enum form, this isn't meant to
// replace AST components.
#[derive(Clone, Debug, strum_macros::Display, strum_macros::IntoStaticStr)]
Expand Down
8 changes: 6 additions & 2 deletions apollo-supergraph/src/lib.rs → apollo-federation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::merge::merge_subgraphs;
use apollo_compiler::ast::Directives;
use apollo_compiler::schema::ExtendedType;
use apollo_compiler::Schema;
use apollo_subgraph::Subgraph;

use crate::merge::merge_subgraphs;
use crate::subgraph::Subgraph;

pub mod database;
pub mod error;
pub mod link;
pub mod merge;
pub mod subgraph;

type MergeError = &'static str;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::{collections::HashMap, sync::Arc};
use apollo_compiler::ast::{Directive, DirectiveLocation, Type};
use apollo_compiler::Schema;

use crate::{
link::{Link, LinkError, LinksMetadata, DEFAULT_LINK_NAME},
use crate::link::{
spec::{Identity, Url},
{Link, LinkError, LinksMetadata, DEFAULT_LINK_NAME},
};

pub fn links_metadata(schema: &Schema) -> Result<Option<LinksMetadata>, LinkError> {
Expand Down Expand Up @@ -148,9 +148,9 @@ fn parse_link_if_bootstrap_directive(schema: &Schema, directive: &Directive) ->

#[cfg(test)]
mod tests {
use crate::{
link::{Import, Purpose},
use crate::link::{
spec::{Version, APOLLO_SPEC_DOMAIN},
{Import, Purpose},
};

use super::*;
Expand Down
11 changes: 8 additions & 3 deletions apollo-at-link/src/link.rs → apollo-federation/src/link/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::spec::Identity;
use crate::spec::Url;
use apollo_compiler::ast::{Directive, Value};
use std::fmt;
use std::str;
use std::{collections::HashMap, sync::Arc};

use apollo_compiler::ast::{Directive, Value};
use thiserror::Error;

use crate::link::spec::Identity;
use crate::link::spec::Url;

pub mod database;
pub mod spec;

pub const DEFAULT_LINK_NAME: &str = "link";
pub const DEFAULT_IMPORT_SCALAR_NAME: &str = "Import";
pub const DEFAULT_PURPOSE_ENUM_NAME: &str = "Purpose";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Identity {
impl fmt::Display for Identity {
/// Display a specification identity.
///
/// # use apollo_at_link::spec::Identity;
/// # use apollo_federation::link::spec::Identity;
/// assert_eq!(
/// Identity { domain: "https://specs.apollo.dev".to_string(), name: "federation".to_string() }.to_string(),
/// "https://specs.apollo.dev/federation"
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct Version {
impl fmt::Display for Version {
/// Display a specification version number.
///
/// # use apollo_at_link::spec::Version;
/// # use apollo_federation::link::spec::Version;
/// assert_eq!(Version { major: 2, minor: 3 }.to_string(), "2.3")
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}.{}", self.major, self.minor)
Expand Down Expand Up @@ -96,7 +96,7 @@ impl str::FromStr for Version {
impl Version {
/// Whether this version satisfies the provided `required` version.
///
/// # use apollo_at_link::spec::Version;
/// # use apollo_federation::link::spec::Version;
/// assert!(&Version { major: 1, minor: 0 }.satisfies(&Version{ major: 1, minor: 0 }));
/// assert!(&Version { major: 1, minor: 2 }.satisfies(&Version{ major: 1, minor: 0 }));
///
Expand All @@ -118,7 +118,7 @@ impl Version {
///
/// # Examples
///
/// # use apollo_at_link::spec::Version;
/// # use apollo_federation::link::spec::Version;
/// assert!(&Version { major: 1, minor: 1 }.satisfies_range(&Version{ major: 1, minor: 0 }, &Version{ major: 1, minor: 10 }));
///
/// assert!(!&Version { major: 2, minor: 0 }.satisfies_range(&Version{ major: 1, minor: 0 }, &Version{ major: 1, minor: 10 }));
Expand All @@ -143,7 +143,7 @@ pub struct Url {
impl fmt::Display for Url {
/// Display a specification url.
///
/// # use apollo_at_link::spec::*;
/// # use apollo_federation::link::spec::*;
/// assert_eq!(
/// Url {
/// identity: Identity { domain: "https://specs.apollo.dev".to_string(), name: "federation".to_string() },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::collections::HashSet;
use std::iter;

use apollo_compiler::ast::Directives;
use apollo_compiler::ast::{
Argument, Directive, DirectiveDefinition, DirectiveLocation, EnumValueDefinition,
Expand All @@ -8,12 +11,11 @@ use apollo_compiler::schema::{
ObjectType, ScalarType, UnionType,
};
use apollo_compiler::{Node, NodeStr, Schema};
use apollo_subgraph::Subgraph;
use indexmap::map::Entry::{Occupied, Vacant};
use indexmap::map::Iter;
use indexmap::{IndexMap, IndexSet};
use std::collections::HashSet;
use std::iter;

use crate::subgraph::Subgraph;

type MergeWarning = &'static str;
type MergeError = &'static str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
use std::sync::Arc;

use apollo_at_link::database::links_metadata;
use apollo_at_link::link::Link;
use apollo_at_link::spec::{Identity, APOLLO_SPEC_DOMAIN};
use apollo_compiler::executable::{Directive, SelectionSet};
use apollo_compiler::Schema;

use crate::link::database::links_metadata;
use crate::link::spec::{Identity, APOLLO_SPEC_DOMAIN};
use crate::link::Link;

// TODO: we should define this as part as some more generic "FederationSpec" definition, but need
// to define the ground work for that in `apollo-at-link` first.
pub fn federation_link_identity() -> Identity {
Expand All @@ -38,6 +39,8 @@ pub struct Key {

impl Key {
// TODO: same remark as above: not meant to be `Option`
// TODO remove suppression OR use method in final version
#[allow(dead_code)]
pub fn selections(&self) -> Option<Arc<SelectionSet>> {
self.selections.clone()
}
Expand All @@ -61,7 +64,7 @@ impl Key {

pub fn federation_link(schema: &Schema) -> Arc<Link> {
links_metadata(schema)
// TODO: error handling?
// TODO: error handling?
.unwrap_or_default()
.unwrap_or_default()
.for_identity(&federation_link_identity())
Expand All @@ -75,6 +78,8 @@ pub fn key_directive_name(schema: &Schema) -> String {
federation_link(schema).directive_name_in_schema("key")
}

// TODO remove suppression OR use method in final version
#[allow(dead_code)]
pub fn keys(schema: &Schema, type_name: &str) -> Vec<Key> {
let key_name = key_directive_name(schema);
if let Some(type_def) = schema.types.get(type_name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use crate::spec::{
AppliedFederationLink, FederationSpecDefinitions, FederationSpecError, LinkSpecDefinitions,
ANY_SCALAR_NAME, ENTITIES_QUERY, ENTITY_UNION_NAME, FEDERATION_V2_DIRECTIVE_NAMES,
KEY_DIRECTIVE_NAME, SERVICE_SDL_QUERY, SERVICE_TYPE,
};
use apollo_at_link::link::LinkError;
use apollo_at_link::link::{self, DEFAULT_LINK_NAME};
use apollo_at_link::spec::Identity;
use std::collections::BTreeMap;
use std::fmt::Formatter;
use std::sync::Arc;

use apollo_compiler::ast::{Name, NamedType};
use apollo_compiler::schema::{ComponentStr, ExtendedType, ObjectType};
use apollo_compiler::{Node, Schema};
use indexmap::map::Entry;
use indexmap::{IndexMap, IndexSet};
use std::collections::BTreeMap;
use std::fmt::Formatter;
use std::sync::Arc;

pub mod database;
use crate::link::spec::Identity;
use crate::link::LinkError;
use crate::link::{Link, DEFAULT_LINK_NAME};
use crate::subgraph::spec::{
AppliedFederationLink, FederationSpecDefinitions, FederationSpecError, LinkSpecDefinitions,
ANY_SCALAR_NAME, ENTITIES_QUERY, ENTITY_UNION_NAME, FEDERATION_V2_DIRECTIVE_NAMES,
KEY_DIRECTIVE_NAME, SERVICE_SDL_QUERY, SERVICE_TYPE,
};

mod database;
mod spec;

// TODO: we need a strategy for errors. All (or almost all) federation errors have a code in
Expand Down Expand Up @@ -94,7 +96,7 @@ impl Subgraph {
.get_all(DEFAULT_LINK_NAME);

for directive in link_directives {
let link_directive = link::Link::from_directive_application(directive)?;
let link_directive = Link::from_directive_application(directive)?;
if link_directive
.url
.identity
Expand Down Expand Up @@ -335,8 +337,9 @@ impl Subgraphs {

#[cfg(test)]
mod tests {
use crate::subgraph::database::keys;

use super::*;
use crate::database::keys;

#[test]
fn can_inspect_a_type_key() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::spec::FederationSpecError::{UnsupportedFederationDirective, UnsupportedVersionError};
use apollo_at_link::link::{
Import, Link, DEFAULT_IMPORT_SCALAR_NAME, DEFAULT_LINK_NAME, DEFAULT_PURPOSE_ENUM_NAME,
};
use apollo_at_link::spec::{Identity, Url, Version};
use std::sync::Arc;

use apollo_compiler::ast::{
Argument, Directive, DirectiveDefinition, DirectiveLocation, EnumValueDefinition,
FieldDefinition, InputValueDefinition, Name, NamedType, Type, Value,
Expand All @@ -12,10 +9,16 @@ use apollo_compiler::schema::{
};
use apollo_compiler::Node;
use indexmap::{IndexMap, IndexSet};
use std::sync::Arc;

use thiserror::Error;

use crate::link::spec::{Identity, Url, Version};
use crate::link::{
Import, Link, DEFAULT_IMPORT_SCALAR_NAME, DEFAULT_LINK_NAME, DEFAULT_PURPOSE_ENUM_NAME,
};
use crate::subgraph::spec::FederationSpecError::{
UnsupportedFederationDirective, UnsupportedVersionError,
};

pub const COMPOSE_DIRECTIVE_NAME: &str = "composeDirective";
pub const KEY_DIRECTIVE_NAME: &str = "key";
pub const EXTENDS_DIRECTIVE_NAME: &str = "extends";
Expand Down Expand Up @@ -624,8 +627,9 @@ impl LinkSpecDefinitions {

#[cfg(test)]
mod tests {
use crate::subgraph::database::federation_link_identity;

use super::*;
use crate::database::federation_link_identity;

#[test]
fn handle_unsupported_federation_version() {
Expand Down
Loading

0 comments on commit 69eccda

Please sign in to comment.