Closed lostman closed 1 year ago
@lostman
ParsedGraphQLSchema
(inside of IndexerSchema
) when web requests come in, so we have a vested interest in not cloning TypeDefinition
s if we don't have to - and keeping this ParsedGraphQLSchema
as small as possible
TypeDefinition
s@ra0x3, if we want to keep it as small as possible, we can remove the following:
ast: ServiceDocument
It is used in only one place:
for definition in schema.ast().definitions.iter() {
if let Some(def) = process_definition(&schema, definition) {
output = quote! {
#output
#def
};
}
}
And process_definition
produces an output only for Type
s
match definition {
TypeSystemDefinition::Type(def) => process_type_def(schema, &def.node),
TypeSystemDefinition::Schema(_def) => None,
def => {
panic!("Unhandled definition type: {def:?}");
}
}
If we want to throw any errors, like the above panic in the case of a Directive,
we can do that at the parser level.
We could instead refer to type_defs
directly:
for (_, type_definition) in schema.type_defs().iter() {
if let Some(def) = process_type_def(&schema, type_definition) {
}
}
Serialize/Deserialize
This poses a problem. The types we use from async-graphql-parser
(e.g., TypeDefinition
) are not serializable. We would have to write a serializer by hand.
Do we really need to serialize this struct? Loading the schema from the DB and parsing it shouldn't be a bottleneck. And for in-memory cache, we shouldn't need to serialize them.
One more thing, in addition to the ServiceDocument
, we keep the raw schema String
inside the ParsedGraphQL
struct. It isn't used anywhere—only the version. So we should only keep the version and the parsed content. I did this in this PR, and I think it is the way to go, but I can always undo this change if needed.
Description
This PR refactors the
ParsedGraphQLSchema::new()
function and removes unnecessary content from the struct.All parsing logic is moved to a separate struct,
SchemaDecoder
.ServiceDocument
and rawGraphQLSchema
are removed fromParsedGraphQLSchema
.ServiceDocument
was only used in the code generator, and we only used the type definitions. We don't need both since we already have these in the parsed content—intype_defs
. As forGraphQLSchema
, we only need the version, not the raw schemaString
.Testing steps
CI testing is sufficient.
Changelog
ParsedGraphQLSchema::new()
and into a separate struct.ast: ServiceDocument
schema: GraphQLSchema
version: String
(the version fromGraphQLSchema
)Please add neat Changelog info here, according to our Contributor's Guide.