Giter VIP home page Giter VIP logo

Comments (4)

syrusakbary avatar syrusakbary commented on August 19, 2024 1

The main reason is:

  • In the first example, the Query object, as inherits more than one ObjectType is automatically mapped to a Union type. Some how graphql doesn't allow union types for the root query object.
  • In the second example, the objects are not inheriting for ObjectType, so when Query inherit those objects is not copying their fields.

However I certainly believe we should be able to do this in a good way.
I'm thinking about create the concept of abstract ObjectTypes so you can extend from them without converting in a UnionType.
Something like:

class Query1(ObjectType):
    class Meta:
        abstract = True
    all_accounts = relay.ConnectionField(accounts_nodes.Account)
    account = relay.NodeField(accounts_nodes.Account)


class Query2(ObjectType):
    class Meta:
        abstract = True
    all_transactions = relay.ConnectionField(accounts_nodes.Transaction)
    transaction = relay.NodeField(accounts_nodes.Transaction)


class Query3(ObjectType):
    class Meta:
        abstract = True
    all_users = relay.ConnectionField(accounts_nodes.User)
    resolve_all_users = ConnectionResolver(accounts_nodes.User)


class Query(Query1, Query2, Query3):
    pass

Thoughts?

from graphene.

adamcharnock avatar adamcharnock commented on August 19, 2024

I think that looks like a good solution. It like that it has some parity with Django's models. Ideally we wouldn't have to specify that a Query is abstract and things would just work, but given that this is not possible I think this is a good solution. 👍

from graphene.

ustun avatar ustun commented on August 19, 2024

This is an interesting topic. Should each django app have its own schema? Then, how do we prevent name collisions? Should we be prefixing the resources then or should each app be serving its own graphql schema at a different URL?

Some of these are subjective, but it would be better if we could give some recommended best practices to the community there.

from graphene.

jcouser avatar jcouser commented on August 19, 2024

Hi,

I'm attempting to create this level of abstraction as well. I'm using graphql-sqlalchemy and when I do something like:

class UserGroupMember(SQLAlchemyObjectType):
    class Meta:
        abstract = True
        model = UserGroupMemberModel
        interfaces = (CustomNode, )

I'm getting the following error:

TypeError: Invalid attributes: abstract

from graphene.

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.