-
Notifications
You must be signed in to change notification settings - Fork 67
enhancement: refactor GraphQL schema parser #1281
Conversation
79d1868
to
924f565
Compare
|
12537fb
to
4d06dce
Compare
@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 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 We could instead refer to for (_, type_definition) in schema.type_defs().iter() {
if let Some(def) = process_type_def(&schema, type_definition) {
}
}
This poses a problem. The types we use from 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this does look cleaner. Will defer to @deekerno
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.