Skip to content

Commit

Permalink
refactor(graph, graphql): avoid duplicating introspection schema
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Jul 18, 2023
1 parent 95e20d5 commit f810f35
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 138 deletions.
9 changes: 8 additions & 1 deletion graph/src/schema/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use inflector::Inflector;
use lazy_static::lazy_static;

use crate::components::store::EntityType;
use crate::data::graphql::ObjectOrInterface;
use crate::data::graphql::{ObjectOrInterface, ObjectTypeExt};
use crate::schema::{ast, META_FIELD_NAME, META_FIELD_TYPE};

use crate::data::graphql::ext::{DirectiveExt, DocumentExt, ValueExt};
Expand Down Expand Up @@ -233,6 +233,13 @@ lazy_static! {
let schema = include_str!("introspection.graphql");
parse_schema(schema).expect("the schema `introspection.graphql` is invalid")
};
pub static ref INTROSPECTION_QUERY_TYPE: ast::ObjectType = ast::ObjectType::from(Arc::new(
INTROSPECTION_SCHEMA.get_root_query_type().unwrap().clone()
));
}

pub fn is_introspection_field(name: &str) -> bool {
INTROSPECTION_QUERY_TYPE.field(name).is_some()
}

fn add_introspection_schema(schema: &mut Document) {
Expand Down
2 changes: 1 addition & 1 deletion graph/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod ast;
mod fulltext;
mod input_schema;

pub use api::{api_schema, APISchemaError};
pub use api::{api_schema, is_introspection_field, APISchemaError, INTROSPECTION_QUERY_TYPE};

pub use api::{ApiSchema, ErrorPolicy};
pub use fulltext::{FulltextAlgorithm, FulltextConfig, FulltextDefinition, FulltextLanguage};
Expand Down
3 changes: 1 addition & 2 deletions graphql/src/execution/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use graph::{
value::{Object, Word},
},
prelude::{s, CheapClone},
schema::META_FIELD_NAME,
schema::{is_introspection_field, INTROSPECTION_QUERY_TYPE, META_FIELD_NAME},
util::{lfu_cache::EvictStats, timed_rw_lock::TimedMutex},
};
use lazy_static::lazy_static;
Expand All @@ -24,7 +24,6 @@ use graph::util::{lfu_cache::LfuCache, stable_hash_glue::impl_stable_hash};

use super::QueryHash;
use crate::execution::ast as a;
use crate::introspection::{is_introspection_field, INTROSPECTION_QUERY_TYPE};
use crate::prelude::*;

lazy_static! {
Expand Down
2 changes: 0 additions & 2 deletions graphql/src/introspection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod resolver;
mod schema;

pub use self::resolver::IntrospectionResolver;
pub use self::schema::{is_introspection_field, INTROSPECTION_DOCUMENT, INTROSPECTION_QUERY_TYPE};
132 changes: 0 additions & 132 deletions graphql/src/introspection/schema.rs

This file was deleted.

0 comments on commit f810f35

Please sign in to comment.