Coder Social home page Coder Social logo

Comments (10)

sunli829 avatar sunli829 commented on April 28, 2024 1

Branch dynamic-interface supports the flatten property, we may need sufficient validation to merge to the master, because this will break the type safety of the interface.

Here are all the tests:

pub async fn test_object_field_flatten() {

pub async fn test_simple_object_field_flatten() {

pub async fn test_object_field_flatten_interface() {

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

This is pretty easy to implement, but I can't make an object that contains the flatten fields support Interface.😭

from async-graphql.

nicolaiunrein avatar nicolaiunrein commented on April 28, 2024

Does that mean you cannot support the flatten attribute on interfaces or objects that use flatten cannot implement an interface? I think having flatten would kind of sort #35 in that you can combine a SimpleObject with an Object.

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

Yes, it's the same problem. I can't pass data between macros, which makes it impossible. But all of these problems can be solved with generic specialization, so let's wait for this feature to stabilize. 😂

from async-graphql.

nicolaiunrein avatar nicolaiunrein commented on April 28, 2024

So I poked around a little in the code base. I tried to manually (without macros) implement an "Object" by implementing ObjectType, OutputValueType and Type on a struct. I can't quite get create_type_info to work correctly but I thought it should be possible to create a trait Merge with required methods async fn base(&self) -> impl ObjectType and async fn extend(&self) -> impl ObjectType and then implement impl<T> ObjectType for T where T: Merge { ... } so that it registers all fields on the object returned from a call to self.base() and self.extend(). Or maybe even a method like async fn objects(&self) -> Vec<Box<dyn ObjectType>>. Could that work or have I hit a dead end?

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

The main reason is that Interface cannot be supported. The field of Interface is function forwarding, which can achieve the purpose of type safety.

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

If I don't need to support the Interface, I've actually implemented it.😁

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

Unless you abandon the type-safety of the interface, which is not what this library is for.

from async-graphql.

sunli829 avatar sunli829 commented on April 28, 2024

The Edge type actually does that, it moves the extra_type to a higher level, but the field inside the extra_type doesn't support interface.

fn Edge::node() and fn Edge::cursor() are actually intended to support the interface.

from async-graphql.

nicolaiunrein avatar nicolaiunrein commented on April 28, 2024

That is very nice! 👍

from async-graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.