update
This commit is contained in:
parent
493ea62ca5
commit
bf2788e11f
22
main.py
22
main.py
@ -12,7 +12,8 @@ class CreateUser(Mutation):
|
||||
|
||||
user = Field(UserType)
|
||||
|
||||
def mutate(self, info, name, age):
|
||||
@staticmethod
|
||||
def mutate(info, name, age):
|
||||
user = {"id": len(Query.users) + 1, "name": name, "age": age}
|
||||
Query.users.append(user)
|
||||
return CreateUser(user=user)
|
||||
@ -37,11 +38,15 @@ class Query(ObjectType):
|
||||
return [user for user in Query.users if user["age"] >= min_age]
|
||||
|
||||
|
||||
class Mut(ObjectType):
|
||||
class Mutation(ObjectType):
|
||||
create_user = CreateUser.Field()
|
||||
|
||||
class UpdateUser(Mutation):
|
||||
class Arguments:
|
||||
name
|
||||
|
||||
schema = Schema(query=Query, mutation=Mut)
|
||||
|
||||
schema = Schema(query=Query, mutation=Mutation)
|
||||
|
||||
gql = """
|
||||
query {
|
||||
@ -64,6 +69,15 @@ mutation{
|
||||
}
|
||||
}
|
||||
"""
|
||||
gql3 = """
|
||||
query {
|
||||
usersByMinAge(minAge: 0) {
|
||||
id
|
||||
name
|
||||
age
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -71,3 +85,5 @@ if __name__ == "__main__":
|
||||
print(res)
|
||||
res = schema.execute(gql2)
|
||||
print(res)
|
||||
res = schema.execute(gql3)
|
||||
print(res)
|
||||
|
Loading…
Reference in New Issue
Block a user