erikwrede / rustberry

Python Bindings for apollo-rs
MIT License
14 stars 0 forks source link

Explore apollo-rs AST -> graphql-core AST conversion #1

Open erikwrede opened 1 year ago

erikwrede commented 1 year ago

After parsing and validation in apollo-rs, we want to convert the AST back to the python format so we don't have to parse the query again to build the pyhton execution context. The conversion should happen as fast as possible to reduce overhead.

Test the following two variants:

erikwrede commented 1 year ago

Mirroring seems to be much faster, but only works by patching the __class__ attribute to get gql-core's isinstance checks to work:

#[pymethods]
impl OperationDefinitionNode {
    #[getter(__class__)]
    pub fn __class__(&self, py: Python<'_>) -> PyResult<PyObject> {
        let field_node = py.import("graphql.language.ast")?.getattr("OperationDefinitionNode")?;
        Ok(field_node.into())
    }
}