Commit 08d2dad0 authored by ymir's avatar ymir
Browse files

graphQL input improvment

parent cc88b6de
......@@ -5,42 +5,42 @@ from dummypythongraphqlserver.graphQL.leaf.client import LeafClientField
from dummypythongraphqlserver.graphQL.leaf.address import LeafAddressField
from dummypythongraphqlserver.graphQL.leaf.purchaseOrder import LeafPurchaseOrderField
from dummypythongraphqlserver.graphQL.leaf.item import LeafItemField
from dummypythongraphqlserver.graphQL.root.client import RootClientField, ReadClientInput, DeleteClients, CreateClients, UpdateClients
from dummypythongraphqlserver.graphQL.root.address import RootAddressField, ReadAddressInput, DeleteAddresses, CreateAddresses, UpdateAddresses
from dummypythongraphqlserver.graphQL.root.purchaseOrder import RootPurchaseOrderField, ReadPurchaseOrderInput, DeletePurchaseOrders, CreatePurchaseOrders, UpdatePurchaseOrders
from dummypythongraphqlserver.graphQL.root.item import RootItemField, ReadItemInput, DeleteItems, CreateItems, UpdateItems
from dummypythongraphqlserver.graphQL.root.client import RootClientField, ReadClientsInput, DeleteClients, CreateClients, UpdateClients
from dummypythongraphqlserver.graphQL.root.address import RootAddressField, ReadAddressesInput, DeleteAddresses, CreateAddresses, UpdateAddresses
from dummypythongraphqlserver.graphQL.root.purchaseOrder import RootPurchaseOrderField, ReadPurchaseOrdersInput, DeletePurchaseOrders, CreatePurchaseOrders, UpdatePurchaseOrders
from dummypythongraphqlserver.graphQL.root.item import RootItemField, ReadItemsInput, DeleteItems, CreateItems, UpdateItems
# query
class Query(ObjectType):
readClients = Field(List(NonNull(RootClientField)),required=True, readClientInput=ReadClientInput(required=True), withAddress=Boolean(), withPurchaseOrders=Boolean(), withOrderLines=Boolean())
readAddresses = Field(List(NonNull(RootAddressField)),required=True, readAddressInput=ReadAddressInput(required=True), withClients=Boolean(), withPurchaseOrders=Boolean(), withOrderLines=Boolean())
readPurchaseOrders = Field(List(NonNull(RootPurchaseOrderField)),required=True, readPurchaseOrderInput=ReadPurchaseOrderInput(required=True), withOrderLines=Boolean(), withClient=Boolean(), withAddress=Boolean())
readItems = Field(List(NonNull(RootItemField)),required=True, readItemInput=ReadItemInput(required=True), withClients=Boolean(), withAddress=Boolean(), withPurchaseOrders=Boolean())
readClients = Field(List(NonNull(RootClientField)),required=True, readClientsInput=ReadClientsInput(required=True), withAddress=Boolean(), withPurchaseOrders=Boolean(), withOrderLines=Boolean())
readAddresses = Field(List(NonNull(RootAddressField)),required=True, readAddressesInput=ReadAddressesInput(required=True), withClients=Boolean(), withPurchaseOrders=Boolean(), withOrderLines=Boolean())
readPurchaseOrders = Field(List(NonNull(RootPurchaseOrderField)),required=True, readPurchaseOrdersInput=ReadPurchaseOrdersInput(required=True), withOrderLines=Boolean(), withClient=Boolean(), withAddress=Boolean())
readItems = Field(List(NonNull(RootItemField)),required=True, readItemsInput=ReadItemsInput(required=True), withClients=Boolean(), withAddress=Boolean(), withPurchaseOrders=Boolean())
'''INFO : keep all parameters, even the ones you do not use later
they will be used by graphen framework
i.e : withAddress, withClient(s), withPurchaseOrders, withOrderLines'''
def resolve_readClients(self, _, readClientInput, withAddress=True, withPurchaseOrders=True, withOrderLines=True):
leafClientFields = LeafClientField.resolveClients(ids=readClientInput.ids, firstName=readClientInput.firstName, lastName=readClientInput.lastName, limit=readClientInput.limit, offset=readClientInput.offset)
def resolve_readClients(self, _, readClientsInput, withAddress=True, withPurchaseOrders=True, withOrderLines=True):
leafClientFields = LeafClientField.resolveClients(ids=readClientsInput.ids, firstName=readClientsInput.firstName, lastName=readClientsInput.lastName, limit=readClientsInput.limit, offset=readClientsInput.offset)
rootClientFields = list()
for leafClientField in leafClientFields:
rootClientField = RootItemField.ClientItemField(id=leafClientField.id, firstName=leafClientField.firstName, lastName=leafClientField.lastName)
rootClientFields.append(rootClientField)
return rootClientFields
def resolve_readAddresses(self, _, readAddressInput, withClients=True, withPurchaseOrders=True, withOrderLines=True):
leafAddressFields = LeafAddressField.resolveAddresses(ids=readAddressInput.ids, houseNumber=readAddressInput.houseNumber, street=readAddressInput.street, zipCode=readAddressInput.zipCode, city=readAddressInput.city, limit=readAddressInput.limit, offset=readAddressInput.offset)
def resolve_readAddresses(self, _, readAddressesInput, withClients=True, withPurchaseOrders=True, withOrderLines=True):
leafAddressFields = LeafAddressField.resolveAddresses(ids=readAddressesInput.ids, houseNumber=readAddressesInput.houseNumber, street=readAddressesInput.street, zipCode=readAddressesInput.zipCode, city=readAddressesInput.city, limit=readAddressesInput.limit, offset=readAddressesInput.offset)
rootAddressFields = list()
for leafAddressField in leafAddressFields:
rootAddressField = RootAddressField(id=leafAddressField.id, houseNumber=leafAddressField.houseNumber, street=leafAddressField.street, zipCode=leafAddressField.zipCode, city=leafAddressField.city)
rootAddressFields.append(rootAddressField)
return rootAddressFields
def resolve_readPurchaseOrders(self, _, readPurchaseOrderInput, withOrderLines=True, withClient=True, withAddress=True):
leafPurchaseOrderFields = LeafPurchaseOrderField.resolvePurchaseOrders(ids=readPurchaseOrderInput.ids, minimumCreationDate=readPurchaseOrderInput.minimumCreationDate, maximumCreationDate=readPurchaseOrderInput.maximumCreationDate, limit=readPurchaseOrderInput.limit, offset=readPurchaseOrderInput.offset)
def resolve_readPurchaseOrders(self, _, readPurchaseOrdersInput, withOrderLines=True, withClient=True, withAddress=True):
leafPurchaseOrderFields = LeafPurchaseOrderField.resolvePurchaseOrders(ids=readPurchaseOrdersInput.ids, minimumCreationDate=readPurchaseOrdersInput.minimumCreationDate, maximumCreationDate=readPurchaseOrdersInput.maximumCreationDate, limit=readPurchaseOrdersInput.limit, offset=readPurchaseOrdersInput.offset)
rootPurchaseOrderFields = list()
for leafPurchaseOrderField in leafPurchaseOrderFields:
rootPurchaseOrderField = RootItemField.ClientItemField.PurchaseOrderClientField( id=leafPurchaseOrderField.id, creationDate=leafPurchaseOrderField.creationDate)
rootPurchaseOrderFields.append(rootPurchaseOrderField)
return rootPurchaseOrderFields
def resolve_readItems(self, _, readItemInput, withClients=True, withAddress=True, withPurchaseOrders=True):
leafItemFields = LeafItemField.resolveItems(ids=readItemInput.ids, name=readItemInput.name, price=readItemInput.price, limit=readItemInput.limit, offset=readItemInput.offset)
def resolve_readItems(self, _, readItemsInput, withClients=True, withAddress=True, withPurchaseOrders=True):
leafItemFields = LeafItemField.resolveItems(ids=readItemsInput.ids, name=readItemsInput.name, price=readItemsInput.price, limit=readItemsInput.limit, offset=readItemsInput.offset)
rootItemFields = list()
for leafItemField in leafItemFields:
rootItemField = RootItemField(id=leafItemField.id, name=leafItemField.name, price=leafItemField.price)
......
......@@ -8,19 +8,19 @@ from dummypythongraphqlserver.graphQL.node.purchaseOrder import NodePurchaseOrde
from dummypythongraphqlserver.graphQL.root import ReadInput, DeleteInput, UpdateInput
from dummypythongraphqlserver.dataAccess.address import AddressDAO
# input
class DeleteAddressInput(DeleteInput, InputObjectType):
class DeleteAddressesInput(DeleteInput, InputObjectType):
houseNumber = Int()
street = String()
zipCode = Int()
city = String()
class ReadAddressInput(ReadInput, DeleteAddressInput):
class ReadAddressesInput(ReadInput, DeleteAddressesInput):
pass
class CreateAddressInput(InputObjectType):
class CreateAddressesInput(InputObjectType):
houseNumber = Int(required=True)
street = String(required=True)
zipCode = Int(required=True)
city = String(required=True)
class UpdateAddressInput(UpdateInput, CreateAddressInput):
class UpdateAddressesInput(UpdateInput, CreateAddressesInput):
pass
# query
class RootAddressField(LeafAddressField):
......@@ -43,40 +43,40 @@ class RootAddressField(LeafAddressField):
# mutation
class DeleteAddresses(Mutation):
class Arguments:
deleteAddressInput = DeleteAddressInput(required=True)
deleteAddressesInput = DeleteAddressesInput(required=True)
# INFO : at least 1 return field is needed by graphene framework
confirmation = Boolean(required=True)
def mutate(self, _, deleteAddressInput):
AddressDAO.delete(ids=deleteAddressInput.ids, houseNumber=deleteAddressInput.houseNumber, street=deleteAddressInput.street, zipCode=deleteAddressInput.zipCode, city=deleteAddressInput.city)
def mutate(self, _, deleteAddressesInput):
AddressDAO.delete(ids=deleteAddressesInput.ids, houseNumber=deleteAddressesInput.houseNumber, street=deleteAddressesInput.street, zipCode=deleteAddressesInput.zipCode, city=deleteAddressesInput.city)
return DeleteAddresses(confirmation=True)
pass
class CreateAddresses(Mutation):
class Arguments:
createAddressInput = List(NonNull(CreateAddressInput), required=True)
createAddressesInput = List(NonNull(CreateAddressesInput), required=True)
withAddress = Boolean()
readAddresses = Field(List(NonNull(LeafAddressField)), required=True)
def mutate(self, _, createAddressInput):
def mutate(self, _, createAddressesInput):
# create each address
entitiesAddressInputs = list()
for lineAddressInput in createAddressInput:
entityAddress = Address(houseNumber=lineAddressInput.houseNumber, street=lineAddressInput.street, zipCode=lineAddressInput.zipCode, city=lineAddressInput.city)
entitiesAddressInputs.append(entityAddress)
entitiesAddressesInputs = list()
for lineAddressesInput in createAddressesInput:
entityAddress = Address(houseNumber=lineAddressesInput.houseNumber, street=lineAddressesInput.street, zipCode=lineAddressesInput.zipCode, city=lineAddressesInput.city)
entitiesAddressesInputs.append(entityAddress)
pass
addressOutputs = AddressDAO.create(entitiesAddressInputs)
addressOutputs = AddressDAO.create(entitiesAddressesInputs)
return CreateAddresses(readAddresses=addressOutputs)
pass
class UpdateAddresses(Mutation):
class Arguments:
updateAddressInput = List(NonNull(UpdateAddressInput), required=True)
updateAddressesInput = List(NonNull(UpdateAddressesInput), required=True)
confirmation = Boolean(required=True)
def mutate(self, _, updateAddressInput):
def mutate(self, _, updateAddressesInput):
# update each address
entitiesAddressInputs = list()
for lineAddressInput in updateAddressInput:
entityAddress = Address(id=lineAddressInput.id, houseNumber=lineAddressInput.houseNumber, street=lineAddressInput.street, zipCode=lineAddressInput.zipCode, city=lineAddressInput.city)
entitiesAddressInputs.append(entityAddress)
entitiesAddressesInputs = list()
for lineAddressesInput in updateAddressesInput:
entityAddress = Address(id=lineAddressesInput.id, houseNumber=lineAddressesInput.houseNumber, street=lineAddressesInput.street, zipCode=lineAddressesInput.zipCode, city=lineAddressesInput.city)
entitiesAddressesInputs.append(entityAddress)
pass
AddressDAO.update(entitiesAddressInputs)
AddressDAO.update(entitiesAddressesInputs)
return UpdateAddresses(confirmation=True)
pass
pass
......@@ -7,16 +7,16 @@ from dummypythongraphqlserver.graphQL.node.purchaseOrder import NodePurchaseOrde
from dummypythongraphqlserver.graphQL.root import ReadInput, DeleteInput, UpdateInput
from dummypythongraphqlserver.dataAccess.client import ClientDAO
# input
class DeleteClientInput(DeleteInput, InputObjectType):
class DeleteClientsInput(DeleteInput, InputObjectType):
firstName = String()
lastName = String()
class ReadClientInput(ReadInput, DeleteClientInput):
class ReadClientsInput(ReadInput, DeleteClientsInput):
pass
class CreateClientInput(InputObjectType):
class CreateClientsInput(InputObjectType):
firstName = String(required=True)
lastName = String(required=True)
addressId = ID(required=True)
class UpdateClientInput(UpdateInput, CreateClientInput):
class UpdateClientsInput(UpdateInput, CreateClientsInput):
pass
# query
class RootClientField(NodeClientField):
......@@ -27,43 +27,43 @@ class RootClientField(NodeClientField):
# mutation
class DeleteClients(Mutation):
class Arguments:
deleteClientInput = DeleteClientInput(required=True)
deleteClientsInput = DeleteClientsInput(required=True)
# INFO : at least 1 return field is needed by graphene framework
confirmation = Boolean(required=True)
def mutate(self, _, deleteClientInput):
ClientDAO.delete(ids=deleteClientInput.ids, firstName=deleteClientInput.firstName, lastName=deleteClientInput.lastName)
def mutate(self, _, deleteClientsInput):
ClientDAO.delete(ids=deleteClientsInput.ids, firstName=deleteClientsInput.firstName, lastName=deleteClientsInput.lastName)
return DeleteClients(confirmation=True)
pass
class CreateClients(Mutation):
class Arguments:
createClientInput = List(NonNull(CreateClientInput), required=True)
createClientsInput = List(NonNull(CreateClientsInput), required=True)
withAddress = Boolean()
readClients = Field(List(NonNull(NodeClientField)), required=True)
'''INFO : keep all parameters, even the ones you do not use later
they will be used by graphen framework
i.e : withAddress, withClient(s), withPurchaseOrders, withOrderLines'''
def mutate(self, _, createClientInput, withAddress=True):
def mutate(self, _, createClientsInput, withAddress=True):
# create each client (and associated address id)
entitiesClientInputs = dict()
for lineClientInput in createClientInput:
entityClient = Client(firstName=lineClientInput.firstName, lastName=lineClientInput.lastName)
entitiesClientInputs[entityClient] = lineClientInput.addressId
entitiesClientsInputs = dict()
for lineClientsInput in createClientsInput:
entityClient = Client(firstName=lineClientsInput.firstName, lastName=lineClientsInput.lastName)
entitiesClientsInputs[entityClient] = lineClientsInput.addressId
pass
clientOutputs = ClientDAO.create(entitiesClientInputs)
clientOutputs = ClientDAO.create(entitiesClientsInputs)
return CreateClients(readClients=clientOutputs)
pass
class UpdateClients(Mutation):
class Arguments:
updateClientInput = List(NonNull(UpdateClientInput), required=True)
updateClientsInput = List(NonNull(UpdateClientsInput), required=True)
confirmation = Boolean(required=True)
def mutate(self, _, updateClientInput):
def mutate(self, _, updateClientsInput):
# update each client (and associated address id)
entitiesClientInputs = dict()
for lineClientInput in updateClientInput:
entityClient = Client(id=lineClientInput.id, firstName=lineClientInput.firstName, lastName=lineClientInput.lastName)
entitiesClientInputs[entityClient] = lineClientInput.addressId
entitiesClientsInputs = dict()
for lineClientsInput in updateClientsInput:
entityClient = Client(id=lineClientsInput.id, firstName=lineClientsInput.firstName, lastName=lineClientsInput.lastName)
entitiesClientsInputs[entityClient] = lineClientsInput.addressId
pass
ClientDAO.update(entitiesClientInputs)
ClientDAO.update(entitiesClientsInputs)
return UpdateClients(confirmation=True)
pass
pass
......@@ -10,15 +10,15 @@ from dummypythongraphqlserver.graphQL.root import ReadInput, DeleteInput, Update
from dummypythongraphqlserver.dataAccess.item import ItemDAO
from dummypythongraphqlserver.dataAccess.orderLine import OrderLineDAO
# input
class DeleteItemInput(DeleteInput, InputObjectType):
class DeleteItemsInput(DeleteInput, InputObjectType):
name = String()
price = String()
class ReadItemInput(ReadInput, DeleteItemInput):
class ReadItemsInput(ReadInput, DeleteItemsInput):
pass
class CreateItemInput(InputObjectType):
class CreateItemsInput(InputObjectType):
name = String(required=True)
price = String(required=True)
class UpdateItemInput(UpdateInput, CreateItemInput):
class UpdateItemsInput(UpdateInput, CreateItemsInput):
pass
# query
class RootItemField(LeafItemField):
......@@ -57,39 +57,39 @@ class RootItemField(LeafItemField):
# mutation
class DeleteItems(Mutation):
class Arguments:
deleteItemInput = DeleteItemInput(required=True)
deleteItemsInput = DeleteItemsInput(required=True)
# INFO : at least 1 return field is needed by graphene framework
confirmation = Boolean(required=True)
def mutate(self, _, deleteItemInput):
ItemDAO.delete(ids=deleteItemInput.ids, name=deleteItemInput.name, price=deleteItemInput.price)
def mutate(self, _, deleteItemsInput):
ItemDAO.delete(ids=deleteItemsInput.ids, name=deleteItemsInput.name, price=deleteItemsInput.price)
return DeleteItems(confirmation=True)
pass
class CreateItems(Mutation):
class Arguments:
createItemInput = List(NonNull(CreateItemInput), required=True)
createItemsInput = List(NonNull(CreateItemsInput), required=True)
readItems = Field(List(NonNull(LeafItemField)), required=True)
def mutate(self, _, createItemInput):
def mutate(self, _, createItemsInput):
# create each item
entitiesItemInputs = list()
for lineItemInput in createItemInput:
entityItem = Item(name=lineItemInput.name, price=lineItemInput.price)
entitiesItemInputs.append(entityItem)
entitiesItemsInputs = list()
for lineItemsInput in createItemsInput:
entityItem = Item(name=lineItemsInput.name, price=lineItemsInput.price)
entitiesItemsInputs.append(entityItem)
pass
itemOutputs = ItemDAO.create(entitiesItemInputs)
itemOutputs = ItemDAO.create(entitiesItemsInputs)
return CreateItems(readItems=itemOutputs)
pass
class UpdateItems(Mutation):
class Arguments:
updateItemInput = List(NonNull(UpdateItemInput), required=True)
updateItemsInput = List(NonNull(UpdateItemsInput), required=True)
confirmation = Boolean(required=True)
def mutate(self, _, updateItemInput):
def mutate(self, _, updateItemsInput):
# update each item
entitiesItemInputs = list()
for lineItemInput in updateItemInput:
entityItem = Item(id=lineItemInput.id, name=lineItemInput.name, price=lineItemInput.price)
entitiesItemInputs.append(entityItem)
entitiesItemsInputs = list()
for lineItemsInput in updateItemsInput:
entityItem = Item(id=lineItemsInput.id, name=lineItemsInput.name, price=lineItemsInput.price)
entitiesItemsInputs.append(entityItem)
pass
ItemDAO.update(entitiesItemInputs)
ItemDAO.update(entitiesItemsInputs)
return UpdateItems(confirmation=True)
pass
pass
......@@ -10,22 +10,22 @@ from dummypythongraphqlserver.graphQL.root import ReadInput, DeleteInput, Update
from dummypythongraphqlserver.dataAccess.purchaseOrder import PurchaseOrderDAO
from dummypythongraphqlserver.dataAccess.orderLine import OrderLineDAO
# input
class DeletePurchaseOrderInput(DeleteInput, InputObjectType):
class DeletePurchaseOrdersInput(DeleteInput, InputObjectType):
minimumCreationDate = Int()
maximumCreationDate = Int()
class ReadPurchaseOrderInput(ReadInput, DeletePurchaseOrderInput):
class ReadPurchaseOrdersInput(ReadInput, DeletePurchaseOrdersInput):
pass
class CreateOrderLineInput(InputObjectType):
quantity = Int(required=True)
itemId = ID(required=True)
class UpdateOrderLineInput(UpdateInput, CreateOrderLineInput):
pass
class WritePurchaseOrderInput(InputObjectType):
class WritePurchaseOrdersInput(InputObjectType):
creationDate = Int(required=True)
clientId = ID(required=True)
class CreatePurchaseOrderInput(WritePurchaseOrderInput):
class CreatePurchaseOrdersInput(WritePurchaseOrdersInput):
orderLines = List(NonNull(CreateOrderLineInput), required=True)
class UpdatePurchaseOrderInput(UpdateInput, WritePurchaseOrderInput):
class UpdatePurchaseOrdersInput(UpdateInput, WritePurchaseOrdersInput):
orderLines = List(NonNull(UpdateOrderLineInput), required=True)
# query
class RootPurchaseOrderField(LeafPurchaseOrderField):
......@@ -41,16 +41,16 @@ class RootPurchaseOrderField(LeafPurchaseOrderField):
# mutation
class DeletePurchaseOrders(Mutation):
class Arguments:
deletePurchaseOrderInput = DeletePurchaseOrderInput(required=True)
deletePurchaseOrdersInput = DeletePurchaseOrdersInput(required=True)
# INFO : at least 1 return field is needed by graphene framework
confirmation = Boolean(required=True)
def mutate(self, _, deletePurchaseOrderInput):
PurchaseOrderDAO.delete(ids=deletePurchaseOrderInput.ids, minimumCreationDate=deletePurchaseOrderInput.minimumCreationDate, maximumCreationDate=deletePurchaseOrderInput.maximumCreationDate)
def mutate(self, _, deletePurchaseOrdersInput):
PurchaseOrderDAO.delete(ids=deletePurchaseOrdersInput.ids, minimumCreationDate=deletePurchaseOrdersInput.minimumCreationDate, maximumCreationDate=deletePurchaseOrdersInput.maximumCreationDate)
return DeletePurchaseOrders(confirmation=True)
pass
class CreatePurchaseOrders(Mutation):
class Arguments:
createPurchaseOrderInput = List(NonNull(CreatePurchaseOrderInput), required=True)
createPurchaseOrdersInput = List(NonNull(CreatePurchaseOrdersInput), required=True)
withClient = Boolean()
withAddress = Boolean()
withOrderLines = Boolean()
......@@ -58,18 +58,18 @@ class CreatePurchaseOrders(Mutation):
'''INFO : keep all parameters, even the ones you do not use later
they will be used by graphen framework
i.e : withAddress, withClient(s), withPurchaseOrders, withOrderLines'''
def mutate(self, _, createPurchaseOrderInput, withClient=True, withAddress=True, withOrderLines=True):
def mutate(self, _, createPurchaseOrdersInput, withClient=True, withAddress=True, withOrderLines=True):
# create each purchase order (and associated client id)
entitiesPurchaseOrderInputs = dict()
for linePurchaseOrderInput in createPurchaseOrderInput:
entityPurchaseOrder = PurchaseOrder(creationDate=linePurchaseOrderInput.creationDate)
entitiesPurchaseOrderInputs[entityPurchaseOrder] = linePurchaseOrderInput.clientId
purchaseOrderOutputs = PurchaseOrderDAO.create(entitiesPurchaseOrderInputs)
entitiesPurchaseOrdersInputs = dict()
for linePurchaseOrdersInput in createPurchaseOrdersInput:
entityPurchaseOrder = PurchaseOrder(creationDate=linePurchaseOrdersInput.creationDate)
entitiesPurchaseOrdersInputs[entityPurchaseOrder] = linePurchaseOrdersInput.clientId
purchaseOrderOutputs = PurchaseOrderDAO.create(entitiesPurchaseOrdersInputs)
# create each order line (and associated order & item ids)
entitiesOrderLineInputs = dict()
for purchaseOrderIndex, linePurchaseOrderInput in enumerate(createPurchaseOrderInput):
for purchaseOrderIndex, linePurchaseOrdersInput in enumerate(createPurchaseOrdersInput):
orderId = purchaseOrderOutputs[purchaseOrderIndex].id
for orderLine in linePurchaseOrderInput.orderLines:
for orderLine in linePurchaseOrdersInput.orderLines:
entityOrderLine = OrderLine(quantity=orderLine.quantity)
entitiesOrderLineInputs[entityOrderLine] = [orderId, orderLine.itemId]
pass
......@@ -79,24 +79,24 @@ class CreatePurchaseOrders(Mutation):
pass
class UpdatePurchaseOrders(Mutation):
class Arguments:
updatePurchaseOrderInput = List(NonNull(UpdatePurchaseOrderInput), required=True)
updatePurchaseOrdersInput = List(NonNull(UpdatePurchaseOrdersInput), required=True)
confirmation = Boolean(required=True)
def mutate(self, _, updatePurchaseOrderInput):
def mutate(self, _, updatePurchaseOrdersInput):
# update each purchase order (and associated client id)
entitiesPurchaseOrderInputs = dict()
entitiesPurchaseOrdersInputs = dict()
orderIds = list()
for linePurchaseOrderInput in updatePurchaseOrderInput:
entityPurchaseOrder = PurchaseOrder(id=linePurchaseOrderInput.id, creationDate=linePurchaseOrderInput.creationDate)
entitiesPurchaseOrderInputs[entityPurchaseOrder] = linePurchaseOrderInput.clientId
orderIds.append(linePurchaseOrderInput.id)
for linePurchaseOrdersInput in updatePurchaseOrdersInput:
entityPurchaseOrder = PurchaseOrder(id=linePurchaseOrdersInput.id, creationDate=linePurchaseOrdersInput.creationDate)
entitiesPurchaseOrdersInputs[entityPurchaseOrder] = linePurchaseOrdersInput.clientId
orderIds.append(linePurchaseOrdersInput.id)
pass
PurchaseOrderDAO.update(entitiesPurchaseOrderInputs)
PurchaseOrderDAO.update(entitiesPurchaseOrdersInputs)
# delete/insert each order line (and associated order & item ids)
OrderLineDAO.delete(orderIds)
entitiesOrderLineInputs = dict()
for linePurchaseOrderInput in updatePurchaseOrderInput:
orderId = linePurchaseOrderInput.id
for orderLine in linePurchaseOrderInput.orderLines:
for linePurchaseOrdersInput in updatePurchaseOrdersInput:
orderId = linePurchaseOrdersInput.id
for orderLine in linePurchaseOrdersInput.orderLines:
entityOrderLine = OrderLine(quantity=orderLine.quantity)
entitiesOrderLineInputs[entityOrderLine] = [orderId, orderLine.itemId]
pass
......
......@@ -6,8 +6,8 @@ from dummypythongraphqlserver.graphQL import schema
from json import loads, dumps
# test class
class testAddress(TestCase):
dynamicQuery = """query ($readAddressInput:ReadAddressInput!,$withClients:Boolean!,$withPurchaseOrders:Boolean!,$withOrderLines:Boolean!) {
readAddresses (readAddressInput:$readAddressInput,withClients:$withClients,withPurchaseOrders:$withPurchaseOrders,withOrderLines:$withOrderLines) {
dynamicQuery = """query ($readAddressesInput:ReadAddressesInput!,$withClients:Boolean!,$withPurchaseOrders:Boolean!,$withOrderLines:Boolean!) {
readAddresses (readAddressesInput:$readAddressesInput,withClients:$withClients,withPurchaseOrders:$withPurchaseOrders,withOrderLines:$withOrderLines) {
houseNumber,
street,
zipCode,
......@@ -31,7 +31,7 @@ class testAddress(TestCase):
}"""
def testAddress00(self):
query = """{
readAddresses (readAddressInput:{street:"st."}) {
readAddresses (readAddressesInput:{street:"st."}) {
id,
houseNumber,
street,
......@@ -45,7 +45,7 @@ class testAddress(TestCase):
pass
def testAddress01(self):
query = """{
readAddresses (readAddressInput:{street:"st.", city:"le"}) {
readAddresses (readAddressesInput:{street:"st.", city:"le"}) {
houseNumber,
street,
zipCode,
......@@ -58,7 +58,7 @@ class testAddress(TestCase):
pass
def testAddress02(self):
query = """{
readAddresses (readAddressInput:{limit:3,offset:2}) {
readAddresses (readAddressesInput:{limit:3,offset:2}) {
id
}
}"""
......@@ -67,56 +67,56 @@ class testAddress(TestCase):
self.assertEqual(loads(dumps(result.data)), expected)
pass
def testAddress03(self):
variables = {"readAddressInput": {"street": "st.", "city": "le"}, "withClients": True, "withPurchaseOrders": False, "withOrderLines": False}
variables = {"readAddressesInput": {"street": "st.", "city": "le"}, "withClients": True, "withPurchaseOrders": False, "withOrderLines": False}
result = schema.execute(testAddress.dynamicQuery,variables=variables)
expected = {'readAddresses': [{'houseNumber': '765', 'street': 'Thomas St.', 'zipCode': '7024', 'city': 'Fort Lee', 'clients': [{'firstName': 'Stephen', 'lastName': 'King'}, {'firstName': 'Stephen', 'lastName': 'Hawking'}]}, {'houseNumber': '23', 'street': 'Ridgeview St.', 'zipCode': '80123', 'city': 'Littleton', 'clients': [{'firstName': 'Taylor', 'lastName': 'Swift'}]}, {'houseNumber': '938', 'street': 'Hanover St.', 'zipCode': '30134', 'city': 'Douglasville', 'clients': []}, {'houseNumber': '81', 'street': 'Aspen St.', 'zipCode': '33823', 'city': 'Auburndale', 'clients': []}]}
self.assertEqual(loads(dumps(result.data)), expected)
pass
def testAddress04(self):
variables = {"readAddressInput": {"street": "st.", "city": "le"}, "withClients": False, "withPurchaseOrders": False, "withOrderLines": False}
variables = {"readAddressesInput": {"street": "st.", "city": "le"}, "withClients": False, "withPurchaseOrders": False, "withOrderLines": False}
result = schema.execute(testAddress.dynamicQuery,variables=variables)
expected = {'readAddresses': [{'houseNumber': '765', 'street': 'Thomas St.', 'zipCode': '7024', 'city': 'Fort Lee'}, {'houseNumber': '23', 'street': 'Ridgeview St.', 'zipCode': '80123', 'city': 'Littleton'}, {'houseNumber': '938', 'street': 'Hanover St.', 'zipCode': '30134', 'city': 'Douglasville'}, {'houseNumber': '81', 'street': 'Aspen St.', 'zipCode': '33823', 'city': 'Auburndale'}]}
self.assertEqual(loads(dumps(result.data)), expected)
pass
def testAddress05(self):
variables = {"readAddressInput": {"street": "st."}, "withClients": True, "withPurchaseOrders": True, "withOrderLines": True}
variables = {"readAddressesInput": {"street": "st."}, "withClients": True, "withPurchaseOrders": True, "withOrderLines": True}
result = schema.execute(testAddress.dynamicQuery,variables=variables)
expected = {'readAddresses': [{'houseNumber': '765', 'street': 'Thomas St.', 'zipCode': '7024', 'city': 'Fort Lee', 'clients': [{'firstName': 'Stephen', 'lastName': 'King', 'purchaseOrders': [{'id': '16', 'creationDate': 20080828, 'orderLines': [{'item': {'name': 'pumpkin pie', 'price': 1.58}, 'quantity': 7}, {'item': {'name': 'pumpkin seeds', 'price': 3.15}, 'quantity': 77}, {'item': {'name': 'chicken (raw)', 'price': 8.4}, 'quantity': 81}]}]}, {'firstName': 'Stephen', 'lastName': 'Hawking', 'purchaseOrders': [{'id': '6', 'creationDate': 20110306, 'orderLines': [{'item': {'name': 'porkchop (cooked)', 'price': 13.65}, 'quantity': 69}]}]}]}, {'houseNumber': '7763', 'street': 'Bedford St.', 'zipCode': '29646', 'city': 'Greenwood', 'clients': [{'firstName': 'Kate', 'lastName': 'Upton', 'purchaseOrders': [{'id': '1', 'creationDate': 20040717, 'orderLines': [{'item': {'name': 'baked potato (cooked)', 'price': 52.5}, 'quantity': 1}, {'item': {'name': 'golden apple', 'price': 40.02}, 'quantity': 89}, {'item': {'name': 'melon (block)', 'price': 25.15}, 'quantity': 95}, {'item': {'name': 'beef/steak (cooked)', 'price': 11.55}, 'quantity': 98}, {'item': {'name': 'sugar cane', 'price': 2.1}, 'quantity': 2}, {'item': {'name': 'melon (slice)', 'price': 2.1}, 'quantity': 59}, {'item': {'name': 'beef/steak (raw)', 'price': 1.05}, 'quantity': 3}, {'item': {'name': 'milk', 'price': 4.5}, 'quantity': 82}]}]}]}, {'houseNumber': '23', 'street': 'Ridgeview St.', 'zipCode': '80123', 'city': 'Littleton', 'clients': [{'firstName': 'Taylor', 'lastName': 'Swift', 'purchaseOrders': []}]}, {'houseNumber': '938', 'street': 'Hanover St.', 'zipCode': '30134', 'city': 'Douglasville', 'clients': []}, {'houseNumber': '7', 'street': 'High St.', 'zipCode': '7032', 'city': 'Kearny', 'clients': []}, {'houseNumber': '81', 'street': 'Aspen St.', 'zipCode': '33823', 'city': 'Auburndale', 'clients': []}]}
self.assertEqual(loads(dumps(result.data)), expected)
pass
def testAddress06(self):
variables = {"readAddressInput": {"street": "st."}, "withClients": False, "withPurchaseOrders": False, "withOrderLines": True}
variables = {"readAddressesInput": {"street": "st."}, "withClients": False, "withPurchaseOrders": False, "withOrderLines": True}
result = schema.execute(testAddress.dynamicQuery,variables=variables)
expected = {'readAddresses': [{'houseNumber': '765', 'street': 'Thomas St.', 'zipCode': '7024', 'city': 'Fort Lee'}, {'houseNumber': '7763', 'street': 'Bedford St.', 'zipCode': '29646', 'city': 'Greenwood'}, {'houseNumber': '23', 'street': 'Ridgeview St.', 'zipCode': '80123', 'city': 'Littleton'}, {'houseNumber': '938', 'street': 'Hanover St.', 'zipCode': '30134', 'city': 'Douglasville'}, {'houseNumber': '7', 'street': 'High St.', 'zipCode': '7032', 'city': 'Kearny'}, {'houseNumber': '81', 'street': 'Aspen St.', 'zipCode': '33823', 'city': 'Auburndale'}]}
self.assertEqual(loads(dumps(result.data)), expected)
pass
def testAddress07(self):
query = """{
readAddresses (readAddressInput:{street: 0}) {
readAddresses (readAddressesInput:{street: 0}) {
id
}
}"""
result = schema.execute(query)
self.assertEqual(result.errors[0].message,"""Argument "readAddressInput" has invalid value {street: 0}.\nIn field "street": Expected type "String", found 0.""")
self.assertEqual(result.errors[0].message,"""Argument "readAddressesInput" has invalid value {street: 0}.\nIn field "street": Expected type "String", found 0.""")
pass
def testAddress08(self):
query = """{
readAddresses (addressInput_:{street: "st."}) {
readAddresses (addressesInput_:{street: "st."}) {
id
}
}"""
result = schema.execute(query)
self.assertEqual(result.errors[0].message,"""Unknown argument "addressInput_" on field "readAddresses" of type "Query". Did you mean "readAddressInput"?""")
self.assertEqual(result.errors[0].message,"""Unknown argument "addressesInput_" on field "readAddresses" of type "Query". Did you mean "readAddressesInput"?""")
pass
def testAddress09(self):
# clean
deleteMutation = """mutation {
deleteAddresses(deleteAddressInput:{houseNumber:1, street:"STREET#", zipCode:10, city:"CITY#"}) {confirmation}
deleteAddresses(deleteAddressesInput:{houseNumber:1, street:"STREET#", zipCode:10, city:"CITY#"}) {confirmation}
}"""
schema.execute(deleteMutation)
# create
mutation = """mutation {
createAddresses (createAddressInput:[{houseNumber:10, street:"STREET#0", zipCode:100, city:"CITY#0"},{houseNumber:11, street:"STREET#1", zipCode:101, city:"CITY#1"}]) {
createAddresses (createAddressesInput:[{houseNumber:10, street:"STREET#0", zipCode:100, city:"CITY#0"},{houseNumber:11, street:"STREET#1", zipCode:101, city:"CITY#1"}]) {
readAddresses {id}
}
}"""
......@@ -127,7 +127,7 @@ class testAddress(TestCase):
ids.append(address["id"])
# update
mutation = """mutation {
updateAddresses (updateAddressInput:[{id:"""+ids[0]+""", houseNumber:12, street:"STREET#2", zipCode:102, city:"CITY#2"},{id:"""+ids[1]+""", houseNumber:103, street:"STREET#3", zipCode:103, city:"CITY#3"}]) {confirmation}
updateAddresses (updateAddressesInput:[{id:"""+ids[0]+""", houseNumber:12, street:"STREET#2", zipCode:102, city:"CITY#2"},{id:"""+ids[1]+""", houseNumber:103, street:"STREET#3", zipCode:103, city:"CITY#3"}]) {confirmation}
}"""
result = schema.execute(mutation)
self.assertTrue(result.data["updateAddresses"]["confirmation"])
......@@ -137,28 +137,28 @@ class testAddress(TestCase):
pass
def testAddress10(self):
# clean
deleteMutation = """mutation deleteMutation ($deleteAddressInput:DeleteAddressInput!) {
deleteAddresses(deleteAddressInput:$deleteAddressInput) {confirmation}
deleteMutation = """mutation deleteMutation ($deleteAddressesInput:DeleteAddressesInput!) {
deleteAddresses(deleteAddressesInput:$deleteAddressesInput) {confirmation}
}"""
deleteVariables = {"deleteAddressInput": {"houseNumber":1, "street":"STREET#", "zipCode":10, "city":"CITY#"}}
deleteVariables = {"deleteAddressesInput": {"houseNumber":1, "street":"STREET#", "zipCode":10, "city":"CITY#"}}
schema.execute(deleteMutation,variables=deleteVariables)
# create
mutation = """mutation createMutation ($createAddressInput:[CreateAddressInput!]!) {
createAddresses (createAddressInput:$createAddressInput) {
mutation = """mutation createMutation ($createAddressesInput:[CreateAddressesInput!]!) {
createAddresses (createAddressesInput:$createAddressesInput) {
readAddresses {id}
}
}"""
variables = {"createAddressInput": [{"houseNumber":10, "street":"STREET#0", "zipCode":100, "city":"CITY#0"},{"houseNumber":11, "street":"STREET#1", "zipCode":101, "city":"CITY#1"}]}
variables = {"createAddressesInput": [{"houseNumber":10, "street":"STREET#0", "zipCode":100, "city":"CITY#0"},{"houseNumber":11, "street":"STREET#1", "zipCode":101, "city":"CITY#1"}]}
result = schema.execute(mutation,variables=variables)
ids=list()
for address in result.data["createAddresses"]["readAddresses"] :
self.assertIsNotNone(address["id"])
ids.append(address["id"])
# update
mutation = """mutation updateMutation ($updateAddressInput:[UpdateAddressInput!]!) {
updateAddresses (updateAddressInput:$updateAddressInput) {confirmation}