Last active
February 1, 2019 21:59
-
-
Save MarkusH/4842a7843ae1934d0fa9aa59ba239662 to your computer and use it in GitHub Desktop.
GraphQL graphene-python pain
This file contains 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
from graphene import Argument, InputObjectType, Mutation, String | |
class ThingInput(InputObjectType): | |
foo = String(required=True) | |
class OtherInput(InputObjectType): | |
bar = String(required=True) | |
class ComponentsInput(InputObjectType): | |
thing = Argument(ThingInput, required=True) | |
other = Argument(OtherInput, required=True) | |
class ProductInput(InputObjectType): | |
description = String(required=True) | |
other = Argument(ComponentsInput, required=True) | |
class CreateProduct(Mutation): | |
id = String() | |
class Arguments: | |
input = Argument(ProductInput, required=True) | |
@staticmethod | |
def mutate(root, info, input): | |
# Do something | |
return CreateProduct(id=...) |
This file contains 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
from graphene import Argument, InputObjectType, Mutation, String | |
class EditThingInput(InputObjectType): | |
foo = String() | |
class EditOtherInput(InputObjectType): | |
bar = String() | |
class EditComponentsInput(InputObjectType): | |
thing = Argument(EditThingInput) | |
other = Argument(EditOtherInput) | |
class EditProductInput(InputObjectType): | |
description = String() | |
other = Argument(EditComponentsInput) | |
class EditProduct(Mutation): | |
id = String() | |
class Arguments: | |
id = String(required=True) | |
patch = Argument(EditProductInput) | |
@staticmethod | |
def mutate(root, info, id, patch): | |
# Fetch product from id | |
# Do something | |
return EditProduct(id=...) |
This file contains 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
from graphene import Field, ObjectType, String | |
class Thing(ObjectType): | |
name = String() | |
class Other(ObjectType): | |
name = String() | |
class Components(ObjectType): | |
thing = Field(Thing) | |
other = Field(Other) | |
class Product(ObjectType): | |
id = String() | |
description = String() | |
components = Field(Components) | |
class Query(ObjectType): | |
product = Field(Product) | |
def resolve_product(self, *args, **kwargs): | |
# Do something | |
return Product(id=..., description=..., components=...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment