func()

in internal/graph/graph.go [37:79]


func (q *GraphQuery) Query(ctx context.Context, query string, subscriptions []*string) *GraphResult {
	result := GraphResult{
		Data: make([]interface{}, 0),
	}

	// Run the query in batches of 300 subscriptions
	batchSize := 300
	for i := 0; i < len(subscriptions); i += batchSize {
		j := i + batchSize
		if j > len(subscriptions) {
			j = len(subscriptions)
		}

		format := arg.ResultFormatObjectArray
		request := arg.QueryRequest{
			Subscriptions: subscriptions[i:j],
			Query:         &query,
			Options: &arg.QueryRequestOptions{
				ResultFormat: &format,
				Top:          to.Ptr(int32(1000)),
			},
		}

		if q.client == nil {
			log.Fatal().Msg("Resource Graph client not initialized")
		}

		var skipToken *string = nil
		for ok := true; ok; ok = skipToken != nil {
			request.Options.SkipToken = skipToken
			// Run the query and get the results
			results, err := q.retry(ctx, 3, 10*time.Second, request)
			if err == nil {
				result.Data = append(result.Data, results.Data.([]interface{})...)
				skipToken = results.SkipToken
			} else {
				log.Fatal().Err(err).Msgf("Failed to run Resource Graph query: %s", query)
				return nil
			}
		}
	}
	return &result
}