GraphQL Queries

We provide a list of sample GraphQL queries that might be usefull for your integration as they mostly come from real world deployments we realized in the past.

Get faces with matches

In order to get all faces with match information with a particular time range use following query:

query GetAllFacesWithMatches(
  $take: Int
  $skip: Int
  $from: DateTime!
  $to: DateTime!
) {
  faces(
    take: $take
    skip: $skip
    order: { createdAt: ASC }
    where: {
      and: [
        { createdAt: { gte: $from } }
        { createdAt: { lte: $to } }
        { matchResults: { any: true } }
      ]
    }
  ) {
    items {
      id
      createdAt
      imageDataId
      matchResults {
        watchlistMemberId
        watchlistMemberFullName
      }
      tracklet {
        id
      }
      frame {
        id
        imageDataId
      }
      cropLeftTopX
      cropLeftTopY
      cropRightTopX
      cropRightTopY
      cropLeftBottomX
      cropLeftBottomY
      cropRightBottomX
      cropRightBottomY
    }
  }
}

Get pedestrians wearing a long sleeve

query pedestriansWithLongSleeve () {
  pedestrians(
    where: {
      objectAttributes: {
        some: {
          type: { 
            in: [LONG_SLEEVE] 
          } 
        }
      }
    }    
  ){
    items {
      id
      objectAttributes {
         type
         floatValue
         boolValue
      }
    } 
  
  }
}

Build a complex pedestrians query

Query adult male pedestrians wearing long sleeve, glasses and having a backpack.

query pedestriansFiltered {
  pedestrians(
    where: {
      and: [
        { objectAttributes: { some: { type: { in: [LONG_SLEEVE] } } } },
        { objectAttributes: { some: { type: { in: [GLASSES] } } } },
        { objectAttributes: { some: { type: { in: [IS_ADULT] } } } },
        { objectAttributes: { some: { type: { in: [IS_MALE] } } } },
        { objectAttributes: { some: { type: { in: [BACKPACK] } } } }
      ]
    }
  ) {
    items {
      id
      objectAttributes {
        type
        floatValue
        boolValue
      }
    }
  }
}

Search using an image

To search in the history of all detected faces using a particular image (of a suspect, for example) we must use two separate queries. First query is using REST API in order to initialize search. Second query then retrieves a results.

  POST   to http://your-smartface-ip:8098/api/v1/Faces/Search with a base64 serialized image:

{
	"image": {
		"data": "/9j/4AAQSkZJRgABAQEAYABgAAD/4
        ....
        +HtO1XVm8RnUdK2W2qC/u9SjNhqN/JF/ouop52Q=="
	},
	"threshold": 50,
	"maxResultCount": 1
}

and you will get a Search Session ID in a response

{
	"searchSessionId": "3f21a452-eb05-4f6a-a692-e77931c1cfba"
}

Query for search results

Use following GraphQL query

query searchByImageResults {
  faces(
    where: {
      searchSessionObjects: {
        some: { searchSessionId: { eq: "3f21a452-eb05-4f6a-a692-e77931c1cfba" } }
      }
    }
  ) {
    items {
      searchSessionObjects {
        score
        searchSessionId
      }
      createdAt
      quality
      matchResults {
        score
      }
      age
      faceArea
      faceAreaChange
      id
      imageDataId
      frame {
        id
        imageDataId
        stream {
          id
          name
        }
      }
    }
    totalCount
  }
}