Created
March 19, 2023 21:46
-
-
Save nietzscheson/e2c3bf5b48a33f2da0adad69508562c2 to your computer and use it in GitHub Desktop.
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
@strawberry.federation.type(keys=["id"]) | |
class UserType: | |
id: strawberry.ID = strawberry.federation.field | |
@classmethod | |
def resolve_reference(cls, id: strawberry.ID): | |
return UserType(id) | |
@strawberry.federation.type(keys=["id"], description="User Type definition") | |
class ProductType: | |
id: strawberry.ID | |
name: str | |
@strawberry.field | |
def created_by(self) -> UserType: | |
return UserType(id=self.created_by) | |
@strawberry.type | |
class Mutation: | |
@strawberry.mutation | |
def product_create(self, name: str, created_by: int) -> ProductType: | |
product = Product(name=name, created_by: int) | |
db.session.add(product) | |
db.session.commit() | |
return product | |
schema = strawberry.federation.Schema(query=Query, types=[UserType, ProductType], mutation=Mutation, enable_federation_2=True) |
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
### User microservice | |
@strawberry.federation.type(keys=["id"]) | |
class UserType: | |
id: strawberry.ID | |
name: str | |
@classmethod | |
def resolve_reference(cls, id: strawberry.ID) -> "UserType": | |
logger.error(id) | |
user = db.session.query(User).get(id) | |
return UserType(id=user.id, name=user.name) | |
@strawberry.type | |
class Mutation: | |
@strawberry.mutation | |
def user_create(self, info: strawberry.types.Info, name: str) -> UserType: | |
user = User(name=name) | |
db.session.add(user) | |
db.session.commit() | |
return user | |
schema = strawberry.federation.Schema(query=Query, types=[UserType], mutation=Mutation, enable_federation_2=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment