Comments (4)
The main reason is:
- In the first example, the
Query
object, as inherits more than oneObjectType
is automatically mapped to aUnion
type. Some howgraphql
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.
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.
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.
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)
- Enum equality comparison is inconsistent
- http://www.graphene-python.org Has EXPIRED HOT 3
- Upload file HOT 2
- Unexpected argument in Pycharm 2023.2.1 HOT 1
- Default_value option in Arguments inside Mutation is not working as expected HOT 2
- Exception: NonNull could not have a mounted String() as inner type. Try with NonNull(String).
- Returning non fatal errors alongside data HOT 1
- Conversion to snake_case fails on nested inputs
- Depth limit validator key error if fragment undefined
- Tests in `graphene/relay/tests/test_custom_global_id.py` fail due incompatibility with pytest 8.x HOT 2
- Enum.from_enum() fails with Django IntegerChoices
- Do you support GQL over websocket? HOT 1
- More documentation for DisableIntrospection?
- Subclass built-in scalars without creating new GraphQL type
- In 3.1.0, `resolve_type` method on Interfaces and Unions no longer supports returning the GraphQL Type as a string HOT 1
- release 3.4.0 HOT 2
- grphene.List not work correctly HOT 1
- When passing the empty string to Date Type, it occurs `IndexError: string index out of range` HOT 2
- Schema execution timing out after upgrade from 2.1.9 to 3.3
- pregenerate schema and cache it for serverless cold start? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene.