Search code examples
hyperledger-fabrichyperledgerhyperledger-composer

Hyperledger Composer query returning blank array


I have the following query defined on my query.qry file:

query selectItemsByOwner { description: "Select all items based on their owner uid" statement: SELECT org.example.auctchain.Item WHERE (owner.uid == _$uid) }

My ACL permission file haves the following rules:

rule Auctioneer {
description: "Allow the auctioneer full access"
participant: "org.example.auctchain.Auctioneer"
operation: ALL
resource: "org.example.auctchain.*"
action: ALLOW
}

rule Member {
description: "Allow the member read access"
participant: "org.example.auctchain.Member"
operation: READ
resource: "org.example.auctchain.*"
action: ALLOW
}

rule VehicleOwner {
description: "Allow the owner of a vehicle total access"
participant(m): "org.example.auctchain.Member"
operation: ALL
resource(v): "org.example.auctchain.Item"
condition: (v.owner.getIdentifier() == m.getIdentifier())
action: ALLOW
}

rule VehicleListingOwner {
description: "Allow the owner of a vehicle total access to their 
vehicle listing"
participant(m): "org.example.auctchain.Member"
operation: ALL
resource(v): "org.example.auctchain.ItemListing"
condition: (v.vehicle.owner.getIdentifier() == m.getIdentifier())
action: ALLOW
}

rule SystemACL {
description:  "System ACL to permit all access"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}

rule NetworkAdminUser {
description: "Grant business network administrators full access to 
user resources"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "**"
action: ALLOW
}

rule NetworkAdminSystem {
description: "Grant business network administrators full access to 
system resources"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}

And my CTO file defines the involved Assets and Participants as follows:

asset Item identified by itemId {
o String itemId
o String name
o ItemType type
--> Member owner
}

abstract participant User identified by uid {
o String uid
o String email
o String firstName
o String lastName
o String phoneNumber
}

participant Member extends User {
o Double balance
}

I updated my package.json version and created the BNA file, then installed it on my network and did the upgrade, everything went fine. Problem comes when I perform this query from either my Angular application or from the Composer REST API Explorer, both return an empty array. Has anybody had this issue? I can't seem to find the fix and it's really bothering me since I really need to perform queries on my app.


Solution

  • First thing, the file name is queries.qry.

    As per my knowledge, currently it is not supported by Hyperledger Composer.

    You can do one thing here, modify your query as below:

    query selectItemsByOwner {
      description: "Select all items based on their owner uid"
      statement:
          SELECT org.dd2.Item
              WHERE (owner == _$owner_res)
    }
    

    and when you execute query, give full resource string as input as shown below:

    resource:org.dd2.Member#m1