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 appearances of an identified person

As a potential source for an attandance system, you might want to get all the appearances of an identified person in front of all cameras.

query GetAppearancesOfIdentifiedPerson(
	$watchlistMemberId: String
    $take: Int
	$skip: Int
	$from: DateTime!
	$to: DateTime!
) {
	matchResults(
		take: $take
		skip: $skip
		order: { createdAt: ASC }
		where: {
			and: [
                { watchlistMemberId:  {
                   eq: $watchlistMemberId
                }}
				{ createdAt: { gte: $from } }
				{ createdAt: { lte: $to } }
			]
		}
	) {
		items {
			id
			createdAt
        
            watchlistMemberId
            watchlistMemberDisplayName

            stream {
                id
                name
            }
		}
	}
}

variables
{
	"watchlistMemberId": "67a45ede-ed09-4074-b5c0-8d0514ee18fe",
	"from": "2025-02-25T00:00:00Z",
	"to": "2025-02-25T23:59:00Z",
	"skip": 0,
	"take": 10
}

Get faces linked with pedestrians

The query allows you to get all the matched faces linked to pedestrians. This code is suitable for pagination code to search through all the data available in the database. The query also provides pedestrian bounding box data. It is suitable for rendering the pedestrians.

query(
  $take: Int
  $skip: Int
  $from: DateTime!
  $to: DateTime!

  ) {
  pedestrians(
    take: $take, 
    skip: $skip, 
    where: {
      processedAt: { 
        gte: $from, 
        lte: $to 
      },
      face: { matchResults :{
        some: {watchlistId: {neq: null}}
      }

      }
    }
  ) {
    items {
      face {
        matchResults {
          watchlistMemberDisplayName
          watchlistMemberFullName
          watchlistId
        }
      }

      processedAt
      streamId
      cropLeftTopX
      cropLeftTopY
      cropRightBottomX
      cropRightBottomY
    }
    
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
  }
}

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
  }
}