Skip to content

Commit

Permalink
docs: add http-client documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Kairo Araujo <[email protected]>
  • Loading branch information
kairoaraujo committed Jan 23, 2025
1 parent 742ec81 commit 75a5462
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/http-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type GraphQLResponseInterface struct {
Errors []api.GraphQLError `json:"errors,omitempty"`
}

// GraphQLRetrieveSubjectResults retrieves the subjects for a given gitoid.
func (ac *ArchivistaClient) GraphQLRetrieveSubjectResults(
ctx context.Context,
gitoid string,
Expand All @@ -113,6 +114,7 @@ func (ac *ArchivistaClient) GraphQLRetrieveSubjectResults(
)
}

// GraphQLRetrieveSearchResults retrieves the search results for a given algorithm and digest.
func (ac *ArchivistaClient) GraphQLRetrieveSearchResults(
ctx context.Context,
algo string,
Expand All @@ -126,6 +128,24 @@ func (ac *ArchivistaClient) GraphQLRetrieveSearchResults(
)
}

// GraphQLQueryIface executes a GraphQL query against the Archivista API and returns the response as an interface.
//
// Parameters:
// - ctx: The context to control the query's lifecycle, such as cancellations or deadlines.
// - query: A string representing the GraphQL query to be executed.
// - variables: A map or struct containing variables to parameterize the query.
//
// Returns:
// - A pointer to a GraphQLResponseInterface containing the query's result or errors.
// - An error if the query execution or response parsing fails.
//
// Example:
//
// response, err := client.GraphQLQueryIface(ctx, query, variables)
// if err != nil {
// log.Fatalf("GraphQL query failed: %v", err)
// }
// fmt.Printf("Response data: %+v\n", response.Data)
func (ac *ArchivistaClient) GraphQLQueryIface(
ctx context.Context,
query string,
Expand All @@ -147,6 +167,7 @@ func (ac *ArchivistaClient) GraphQLQueryIface(
return &gqlRes, nil

Check warning on line 167 in pkg/http-client/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/http-client/client.go#L153-L167

Added lines #L153 - L167 were not covered by tests
}

// GraphQLQueryToDst executes a GraphQL query against the Archivista API and unmarshals the response into a destination object.
func (ac *ArchivistaClient) GraphQLQueryToDst(ctx context.Context, query string, variables interface{}, dst interface{}) error {
reader, err := ac.GraphQLQueryReadCloser(ctx, query, variables)
if err != nil {
Expand All @@ -160,6 +181,7 @@ func (ac *ArchivistaClient) GraphQLQueryToDst(ctx context.Context, query string,
return nil

Check warning on line 181 in pkg/http-client/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/http-client/client.go#L171-L181

Added lines #L171 - L181 were not covered by tests
}

// GraphQLQueryReadCloser executes a GraphQL query against the Archivista API and returns the response as an io.ReadCloser.
func (ac *ArchivistaClient) GraphQLQueryReadCloser(
ctx context.Context,
query string,
Expand Down

0 comments on commit 75a5462

Please sign in to comment.