Ability to have one class per query instead of one method per query
See original GitHub issue[x] Feature request
[x] Or - Docs request
graphene==2.1.0
Is it possible to have a similar pattern for queries, similar to mutation. This is to avoid long classes with multiple resolvers.
It would be great if this would be possible.
# mutation -- working example
class JwtRefreshMutation(graphene.Mutation):
class Arguments:
token=graphene.String(required=True)
token = graphene.String()
def mutate(self, info, **args):
token = refresh_token(args['token'])
return JwtRefreshMutation(token=token)
class Mutations(graphene.ObjectType):
jwt_refresh = JwtRefreshMutation.Field()
# query -- desired example
class JwtRefreshQuery(graphene.Query):
class Arguments:
token=graphene.String(required=True)
token = graphene.String()
def resolve(self, info, **args):
token = refresh_token(args['token'])
return JwtRefreshQuery(token=token)
class Query(graphene.ObjectType):
jwt_refresh = JwtRefreshQuery.Field()
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Best way to structure multiple queries in one method c# asp.net
IMO, the best way is to use one connection for one query. You want to execute another query? Set up another connection. :)...
Read more >Defining and Using Class Queries
Describes how to define and use class queries, named queries that are defined in a class and can be accessed using dynamic SQL....
Read more >Use a union query to combine multiple queries into a single ...
The second part of this SQL statement is the UNION keyword which tells Access that this query will combine these two sets of...
Read more >Best practices for querying and scanning data
Follow these best practices for Query and Scan operations using DynamoDB. ... We recommend that you begin with a simple ratio, such as...
Read more >Creating database connections - Do it once or for each query?
-1 The answer is rather misleading. Creating a connection per query is a very bad idea. What you probably mean is "retrieve a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I’ve been thinking about this a lot and I think that being able to define a class to resolve an
ObjectType
would be quite useful. I’ve got some working code based on theMutation
class @un33k if you want to include it in your application and see if it works:You use it in pretty much the way you want to in your example:
I’m not sure what to call it at the moment or where it might fit in in the project. It might even be that the
ObjectType
class should be extended to allow this kind of use. Any thoughts @syrusakbary ?Hi,
you can do like this:
I agree intuitively I think it would make more sense if the API for mutations and queries were more similar. In any case yes the docs/examles are a bit lacking in showing how you can do “merge multiple query classes”