Created
April 5, 2021 19:04
-
-
Save alexanderhupfer/4602edfdd99f39ecfa21d8142a775b0c to your computer and use it in GitHub Desktop.
Customising a python-graphene SQLAlchemy Query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Configuration(graphene.ObjectType): | |
#ID! definition to be ommitted, generated by node interface | |
enabled = graphene.Boolean() | |
value = graphene.Int() | |
class Meta: | |
interfaces = (relay.Node, ) | |
def query_Configuration(user_id): | |
configuration = get_user_configuration(user_id) | |
result = { | |
'enabled' : configuration.enabled, | |
'value' : configuration.value, | |
'id': configuration.id | |
} | |
return result | |
class User(SQLAlchemyObjectType): | |
class Meta: | |
model = UserModel | |
configuration = graphene.Field(lambda: Confguration) | |
def resolve_configuration(self, info, **kwargs): | |
return resolve_configuration(user_id=self.id) | |
class Query(graphene.ObjectType): | |
node = relay.Node.Field() | |
user = graphene.Field(User, | |
id=graphene.String(required=True)) | |
def resolve_user( | |
args, | |
info, | |
id, **kwargs): | |
user = SqlAlchermyQuery(id) # return UserModel from sqlAlchemy | |
return user | |
schema = graphene.Schema(query=Query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment