diff --git a/pkg/assembler/backends/arangodb/hasSBOM_test.go b/pkg/assembler/backends/arangodb/hasSBOM_test.go index 408cb36a3cd..ade850d48d6 100644 --- a/pkg/assembler/backends/arangodb/hasSBOM_test.go +++ b/pkg/assembler/backends/arangodb/hasSBOM_test.go @@ -996,7 +996,8 @@ func Test_buildHasSbomByID(t *testing.T) { } } for _, o := range test.Calls { - found, err := b.IngestHasSbom(ctx, o.Sub, *o.HS) + // TODO (knrc) handle includes + found, err := b.IngestHasSbom(ctx, o.Sub, *o.HS, model.HasSBOMIncludesInputSpec{}) if (err != nil) != test.ExpIngestErr { t.Fatalf("did not get expected ingest error, want: %v, got: %v", test.ExpIngestErr, err) } diff --git a/pkg/assembler/backends/arangodb/path_test.go b/pkg/assembler/backends/arangodb/path_test.go index 102d9214ecb..45e5758931f 100644 --- a/pkg/assembler/backends/arangodb/path_test.go +++ b/pkg/assembler/backends/arangodb/path_test.go @@ -665,7 +665,8 @@ func Test_Nodes(t *testing.T) { nodeID = found.ID } if tt.hasSBOMCall != nil { - found, err := b.IngestHasSbom(ctx, tt.hasSBOMCall.Sub, *tt.hasSBOMCall.HS) + // TODO (knrc) handle includes + found, err := b.IngestHasSbom(ctx, tt.hasSBOMCall.Sub, *tt.hasSBOMCall.HS, model.HasSBOMIncludesInputSpec{}) if (err != nil) != tt.wantErr { t.Fatalf("did not get expected ingest error, want: %v, got: %v", tt.wantErr, err) } diff --git a/pkg/assembler/backends/inmem/path_test.go b/pkg/assembler/backends/inmem/path_test.go index bbdf23bcf39..7acc5bfac52 100644 --- a/pkg/assembler/backends/inmem/path_test.go +++ b/pkg/assembler/backends/inmem/path_test.go @@ -335,9 +335,24 @@ func Test_Nodes(t *testing.T) { }}, }, { name: "hasSBOM", - inPkg: []*model.PkgInputSpec{testdata.P1}, + inPkg: []*model.PkgInputSpec{testdata.P1, testdata.P2}, + inArt: []*model.ArtifactInputSpec{testdata.A1}, + isDepCall: &isDepCall{ + P1: testdata.P1, + P2: testdata.P2, + MF: mAll, + ID: &model.IsDependencyInputSpec{}, + }, + isOcurCall: &isOcurCall{ + PkgSrc: model.PackageOrSourceInput{ + Package: testdata.P1, + }, + Artifact: testdata.A1, + Occurrence: &model.IsOccurrenceInputSpec{ + Justification: "test justification", + }, + }, hasSBOMCall: &hasSBOMCall{ - Sub: model.PackageOrArtifactInput{ Package: testdata.P1, }, @@ -346,10 +361,14 @@ func Test_Nodes(t *testing.T) { }, }, want: []model.Node{&model.HasSbom{ - Subject: testdata.P1out, - DownloadLocation: "location two", + Subject: testdata.P1out, + DownloadLocation: "location two", + IncludedSoftware: []model.PackageOrArtifact{model.Package{ID: "4"}, model.Package{ID: "5"}, model.Artifact{ID: "6"}}, + IncludedDependencies: []*model.IsDependency{{ID: "7"}}, + IncludedOccurrences: []*model.IsOccurrence{{ID: "8"}}, }}, }, { + name: "hasSLSA", inArt: []*model.ArtifactInputSpec{testdata.A1, testdata.A2}, inBld: []*model.BuilderInputSpec{testdata.B1, testdata.B2}, @@ -501,9 +520,12 @@ func Test_Nodes(t *testing.T) { t.Fatalf("Could not instantiate testing backend: %v", err) } var nodeID string + includes := model.HasSBOMIncludesInputSpec{} for _, p := range tt.inPkg { - if _, err := b.IngestPackage(ctx, *p); err != nil { + if pkg, err := b.IngestPackage(ctx, *p); err != nil { t.Fatalf("Could not ingest package: %v", err) + } else { + includes.Software = append(includes.Software, pkg.Namespaces[0].Names[0].Versions[0].ID) } } for _, s := range tt.inSrc { @@ -512,8 +534,10 @@ func Test_Nodes(t *testing.T) { } } for _, a := range tt.inArt { - if _, err := b.IngestArtifact(ctx, a); err != nil { + if art, err := b.IngestArtifact(ctx, a); err != nil { t.Fatalf("Could not ingest artifact: %v", err) + } else { + includes.Software = append(includes.Software, art.ID) } } for _, bld := range tt.inBld { @@ -538,6 +562,7 @@ func Test_Nodes(t *testing.T) { return } nodeID = ingestedPkg.Namespaces[0].Names[0].Versions[0].ID + includes.Software = append(includes.Software, nodeID) } if tt.artifactInput != nil { ingestedArt, err := b.IngestArtifact(ctx, tt.artifactInput) @@ -658,16 +683,6 @@ func Test_Nodes(t *testing.T) { } nodeID = found.ID } - if tt.hasSBOMCall != nil { - found, err := b.IngestHasSbom(ctx, tt.hasSBOMCall.Sub, *tt.hasSBOMCall.HS) - if (err != nil) != tt.wantErr { - t.Fatalf("did not get expected ingest error, want: %v, got: %v", tt.wantErr, err) - } - if err != nil { - return - } - nodeID = found.ID - } if tt.hasSlsaCall != nil { found, err := b.IngestSLSA(ctx, *tt.hasSlsaCall.Sub, tt.hasSlsaCall.BF, *tt.hasSlsaCall.BB, *tt.hasSlsaCall.SLSA) if (err != nil) != tt.wantErr { @@ -697,6 +712,7 @@ func Test_Nodes(t *testing.T) { return } nodeID = found.ID + includes.Dependencies = append(includes.Dependencies, nodeID) } if tt.isOcurCall != nil { found, err := b.IngestOccurrence(ctx, tt.isOcurCall.PkgSrc, *tt.isOcurCall.Artifact, *tt.isOcurCall.Occurrence) @@ -707,6 +723,18 @@ func Test_Nodes(t *testing.T) { return } nodeID = found.ID + includes.Occurrences = append(includes.Occurrences, nodeID) + } + if tt.hasSBOMCall != nil { + // After isDepCall and isOcurCall so they can set up includes. + found, err := b.IngestHasSbom(ctx, tt.hasSBOMCall.Sub, *tt.hasSBOMCall.HS, includes) + if (err != nil) != tt.wantErr { + t.Fatalf("did not get expected ingest error, want: %v, got: %v", tt.wantErr, err) + } + if err != nil { + return + } + nodeID = found.ID } if tt.pkgEqualCall != nil { found, err := b.IngestPkgEqual(ctx, *tt.pkgEqualCall.P1, *tt.pkgEqualCall.P2, *tt.pkgEqualCall.HE) diff --git a/pkg/assembler/clients/generated/operations.go b/pkg/assembler/clients/generated/operations.go index 7b3934cb9c1..4950e87be03 100644 --- a/pkg/assembler/clients/generated/operations.go +++ b/pkg/assembler/clients/generated/operations.go @@ -8029,113 +8029,6 @@ func (v *HashEqualInputSpec) GetOrigin() string { return v.Origin } // GetCollector returns HashEqualInputSpec.Collector, and is useful for accessing the field via an interface. func (v *HashEqualInputSpec) GetCollector() string { return v.Collector } -// IdPkgTree includes the GraphQL fields of Package requested by the fragment IdPkgTree. -// The GraphQL type's documentation follows. -// -// Package represents the root of the package trie/tree. -// -// We map package information to a trie, closely matching the pURL specification -// (https://github.com/package-url/purl-spec/blob/0dd92f26f8bb11956ffdf5e8acfcee71e8560407/README.rst), -// but deviating from it where GUAC heuristics allow for better representation of -// package information. Each path in the trie fully represents a package; we split -// the trie based on the pURL components. -// -// This node matches a pkg: partial pURL. The type field matches the -// pURL types but we might also use "guac" for the cases where the pURL -// representation is not complete or when we have custom rules. -// -// Since this node is at the root of the package trie, it is named Package, not -// PackageType. -type IdPkgTree struct { - Id string `json:"id"` - Namespaces []IdPkgTreeNamespacesPackageNamespace `json:"namespaces"` -} - -// GetId returns IdPkgTree.Id, and is useful for accessing the field via an interface. -func (v *IdPkgTree) GetId() string { return v.Id } - -// GetNamespaces returns IdPkgTree.Namespaces, and is useful for accessing the field via an interface. -func (v *IdPkgTree) GetNamespaces() []IdPkgTreeNamespacesPackageNamespace { return v.Namespaces } - -// IdPkgTreeNamespacesPackageNamespace includes the requested fields of the GraphQL type PackageNamespace. -// The GraphQL type's documentation follows. -// -// PackageNamespace is a namespace for packages. -// -// In the pURL representation, each PackageNamespace matches the -// pkg:// partial pURL. -// -// Namespaces are optional and type specific. Because they are optional, we use -// empty string to denote missing namespaces. -type IdPkgTreeNamespacesPackageNamespace struct { - Id string `json:"id"` - Names []IdPkgTreeNamespacesPackageNamespaceNamesPackageName `json:"names"` -} - -// GetId returns IdPkgTreeNamespacesPackageNamespace.Id, and is useful for accessing the field via an interface. -func (v *IdPkgTreeNamespacesPackageNamespace) GetId() string { return v.Id } - -// GetNames returns IdPkgTreeNamespacesPackageNamespace.Names, and is useful for accessing the field via an interface. -func (v *IdPkgTreeNamespacesPackageNamespace) GetNames() []IdPkgTreeNamespacesPackageNamespaceNamesPackageName { - return v.Names -} - -// IdPkgTreeNamespacesPackageNamespaceNamesPackageName includes the requested fields of the GraphQL type PackageName. -// The GraphQL type's documentation follows. -// -// PackageName is a name for packages. -// -// In the pURL representation, each PackageName matches the -// pkg:// pURL. -// -// Names are always mandatory. -// -// This is the first node in the trie that can be referred to by other parts of -// GUAC. -type IdPkgTreeNamespacesPackageNamespaceNamesPackageName struct { - Id string `json:"id"` - Versions []IdPkgTreeNamespacesPackageNamespaceNamesPackageNameVersionsPackageVersion `json:"versions"` -} - -// GetId returns IdPkgTreeNamespacesPackageNamespaceNamesPackageName.Id, and is useful for accessing the field via an interface. -func (v *IdPkgTreeNamespacesPackageNamespaceNamesPackageName) GetId() string { return v.Id } - -// GetVersions returns IdPkgTreeNamespacesPackageNamespaceNamesPackageName.Versions, and is useful for accessing the field via an interface. -func (v *IdPkgTreeNamespacesPackageNamespaceNamesPackageName) GetVersions() []IdPkgTreeNamespacesPackageNamespaceNamesPackageNameVersionsPackageVersion { - return v.Versions -} - -// IdPkgTreeNamespacesPackageNamespaceNamesPackageNameVersionsPackageVersion includes the requested fields of the GraphQL type PackageVersion. -// The GraphQL type's documentation follows. -// -// PackageVersion is a package version. -// -// In the pURL representation, each PackageName matches the -// pkg://@ pURL. -// -// Versions are optional and each Package type defines own rules for handling -// them. For this level of GUAC, these are just opaque strings. -// -// NOTE: The handling of versions might change before this schema becomes stable. -// -// This node can be referred to by other parts of GUAC. -// -// Subpath and qualifiers are optional. Lack of qualifiers is represented by an -// empty list and lack of subpath by empty string (to be consistent with -// optionality of namespace and version). Two nodes that have different qualifiers -// and/or subpath but the same version mean two different packages in the trie -// (they are different). Two nodes that have same version but qualifiers of one -// are a subset of the qualifier of the other also mean two different packages in -// the trie. -type IdPkgTreeNamespacesPackageNamespaceNamesPackageNameVersionsPackageVersion struct { - Id string `json:"id"` -} - -// GetId returns IdPkgTreeNamespacesPackageNamespaceNamesPackageNameVersionsPackageVersion.Id, and is useful for accessing the field via an interface. -func (v *IdPkgTreeNamespacesPackageNamespaceNamesPackageNameVersionsPackageVersion) GetId() string { - return v.Id -} - // IngestArtifactResponse is returned by IngestArtifact on success. type IngestArtifactResponse struct { // Ingests a new artifact and returns it. The returned ID can be empty string. @@ -8226,175 +8119,79 @@ type IngestLicensesResponse struct { // GetIngestLicenses returns IngestLicensesResponse.IngestLicenses, and is useful for accessing the field via an interface. func (v *IngestLicensesResponse) GetIngestLicenses() []string { return v.IngestLicenses } -// IngestPackageIngestPackage includes the requested fields of the GraphQL type Package. +// IngestPackageIngestPackagePackageIDs includes the requested fields of the GraphQL type PackageIDs. // The GraphQL type's documentation follows. // -// Package represents the root of the package trie/tree. -// -// We map package information to a trie, closely matching the pURL specification -// (https://github.com/package-url/purl-spec/blob/0dd92f26f8bb11956ffdf5e8acfcee71e8560407/README.rst), -// but deviating from it where GUAC heuristics allow for better representation of -// package information. Each path in the trie fully represents a package; we split -// the trie based on the pURL components. -// -// This node matches a pkg: partial pURL. The type field matches the -// pURL types but we might also use "guac" for the cases where the pURL -// representation is not complete or when we have custom rules. -// -// Since this node is at the root of the package trie, it is named Package, not -// PackageType. -type IngestPackageIngestPackage struct { - IdPkgTree `json:"-"` -} - -// GetId returns IngestPackageIngestPackage.Id, and is useful for accessing the field via an interface. -func (v *IngestPackageIngestPackage) GetId() string { return v.IdPkgTree.Id } - -// GetNamespaces returns IngestPackageIngestPackage.Namespaces, and is useful for accessing the field via an interface. -func (v *IngestPackageIngestPackage) GetNamespaces() []IdPkgTreeNamespacesPackageNamespace { - return v.IdPkgTree.Namespaces -} - -func (v *IngestPackageIngestPackage) UnmarshalJSON(b []byte) error { - - if string(b) == "null" { - return nil - } - - var firstPass struct { - *IngestPackageIngestPackage - graphql.NoUnmarshalJSON - } - firstPass.IngestPackageIngestPackage = v - - err := json.Unmarshal(b, &firstPass) - if err != nil { - return err - } - - err = json.Unmarshal( - b, &v.IdPkgTree) - if err != nil { - return err - } - return nil +// The IDs of the ingested package +type IngestPackageIngestPackagePackageIDs struct { + PackageTypeID string `json:"packageTypeID"` + PackageNamespaceID string `json:"packageNamespaceID"` + PackageNameID string `json:"packageNameID"` + PackageVersionID string `json:"packageVersionID"` } -type __premarshalIngestPackageIngestPackage struct { - Id string `json:"id"` +// GetPackageTypeID returns IngestPackageIngestPackagePackageIDs.PackageTypeID, and is useful for accessing the field via an interface. +func (v *IngestPackageIngestPackagePackageIDs) GetPackageTypeID() string { return v.PackageTypeID } - Namespaces []IdPkgTreeNamespacesPackageNamespace `json:"namespaces"` +// GetPackageNamespaceID returns IngestPackageIngestPackagePackageIDs.PackageNamespaceID, and is useful for accessing the field via an interface. +func (v *IngestPackageIngestPackagePackageIDs) GetPackageNamespaceID() string { + return v.PackageNamespaceID } -func (v *IngestPackageIngestPackage) MarshalJSON() ([]byte, error) { - premarshaled, err := v.__premarshalJSON() - if err != nil { - return nil, err - } - return json.Marshal(premarshaled) -} - -func (v *IngestPackageIngestPackage) __premarshalJSON() (*__premarshalIngestPackageIngestPackage, error) { - var retval __premarshalIngestPackageIngestPackage +// GetPackageNameID returns IngestPackageIngestPackagePackageIDs.PackageNameID, and is useful for accessing the field via an interface. +func (v *IngestPackageIngestPackagePackageIDs) GetPackageNameID() string { return v.PackageNameID } - retval.Id = v.IdPkgTree.Id - retval.Namespaces = v.IdPkgTree.Namespaces - return &retval, nil +// GetPackageVersionID returns IngestPackageIngestPackagePackageIDs.PackageVersionID, and is useful for accessing the field via an interface. +func (v *IngestPackageIngestPackagePackageIDs) GetPackageVersionID() string { + return v.PackageVersionID } // IngestPackageResponse is returned by IngestPackage on success. type IngestPackageResponse struct { // Ingests a new package and returns a corresponding package hierarchy containing only the IDs. The returned ID can be empty string. - IngestPackage IngestPackageIngestPackage `json:"ingestPackage"` + IngestPackage IngestPackageIngestPackagePackageIDs `json:"ingestPackage"` } // GetIngestPackage returns IngestPackageResponse.IngestPackage, and is useful for accessing the field via an interface. -func (v *IngestPackageResponse) GetIngestPackage() IngestPackageIngestPackage { return v.IngestPackage } +func (v *IngestPackageResponse) GetIngestPackage() IngestPackageIngestPackagePackageIDs { + return v.IngestPackage +} -// IngestPackagesIngestPackagesPackage includes the requested fields of the GraphQL type Package. +// IngestPackagesIngestPackagesPackageIDs includes the requested fields of the GraphQL type PackageIDs. // The GraphQL type's documentation follows. // -// Package represents the root of the package trie/tree. -// -// We map package information to a trie, closely matching the pURL specification -// (https://github.com/package-url/purl-spec/blob/0dd92f26f8bb11956ffdf5e8acfcee71e8560407/README.rst), -// but deviating from it where GUAC heuristics allow for better representation of -// package information. Each path in the trie fully represents a package; we split -// the trie based on the pURL components. -// -// This node matches a pkg: partial pURL. The type field matches the -// pURL types but we might also use "guac" for the cases where the pURL -// representation is not complete or when we have custom rules. -// -// Since this node is at the root of the package trie, it is named Package, not -// PackageType. -type IngestPackagesIngestPackagesPackage struct { - IdPkgTree `json:"-"` -} - -// GetId returns IngestPackagesIngestPackagesPackage.Id, and is useful for accessing the field via an interface. -func (v *IngestPackagesIngestPackagesPackage) GetId() string { return v.IdPkgTree.Id } - -// GetNamespaces returns IngestPackagesIngestPackagesPackage.Namespaces, and is useful for accessing the field via an interface. -func (v *IngestPackagesIngestPackagesPackage) GetNamespaces() []IdPkgTreeNamespacesPackageNamespace { - return v.IdPkgTree.Namespaces -} - -func (v *IngestPackagesIngestPackagesPackage) UnmarshalJSON(b []byte) error { - - if string(b) == "null" { - return nil - } - - var firstPass struct { - *IngestPackagesIngestPackagesPackage - graphql.NoUnmarshalJSON - } - firstPass.IngestPackagesIngestPackagesPackage = v - - err := json.Unmarshal(b, &firstPass) - if err != nil { - return err - } - - err = json.Unmarshal( - b, &v.IdPkgTree) - if err != nil { - return err - } - return nil +// The IDs of the ingested package +type IngestPackagesIngestPackagesPackageIDs struct { + PackageTypeID string `json:"packageTypeID"` + PackageNamespaceID string `json:"packageNamespaceID"` + PackageNameID string `json:"packageNameID"` + PackageVersionID string `json:"packageVersionID"` } -type __premarshalIngestPackagesIngestPackagesPackage struct { - Id string `json:"id"` +// GetPackageTypeID returns IngestPackagesIngestPackagesPackageIDs.PackageTypeID, and is useful for accessing the field via an interface. +func (v *IngestPackagesIngestPackagesPackageIDs) GetPackageTypeID() string { return v.PackageTypeID } - Namespaces []IdPkgTreeNamespacesPackageNamespace `json:"namespaces"` +// GetPackageNamespaceID returns IngestPackagesIngestPackagesPackageIDs.PackageNamespaceID, and is useful for accessing the field via an interface. +func (v *IngestPackagesIngestPackagesPackageIDs) GetPackageNamespaceID() string { + return v.PackageNamespaceID } -func (v *IngestPackagesIngestPackagesPackage) MarshalJSON() ([]byte, error) { - premarshaled, err := v.__premarshalJSON() - if err != nil { - return nil, err - } - return json.Marshal(premarshaled) -} +// GetPackageNameID returns IngestPackagesIngestPackagesPackageIDs.PackageNameID, and is useful for accessing the field via an interface. +func (v *IngestPackagesIngestPackagesPackageIDs) GetPackageNameID() string { return v.PackageNameID } -func (v *IngestPackagesIngestPackagesPackage) __premarshalJSON() (*__premarshalIngestPackagesIngestPackagesPackage, error) { - var retval __premarshalIngestPackagesIngestPackagesPackage - - retval.Id = v.IdPkgTree.Id - retval.Namespaces = v.IdPkgTree.Namespaces - return &retval, nil +// GetPackageVersionID returns IngestPackagesIngestPackagesPackageIDs.PackageVersionID, and is useful for accessing the field via an interface. +func (v *IngestPackagesIngestPackagesPackageIDs) GetPackageVersionID() string { + return v.PackageVersionID } // IngestPackagesResponse is returned by IngestPackages on success. type IngestPackagesResponse struct { // Bulk ingests packages and returns the list of corresponding package hierarchies containing only the IDs. The returned array of IDs can be empty strings. - IngestPackages []IngestPackagesIngestPackagesPackage `json:"ingestPackages"` + IngestPackages []IngestPackagesIngestPackagesPackageIDs `json:"ingestPackages"` } // GetIngestPackages returns IngestPackagesResponse.IngestPackages, and is useful for accessing the field via an interface. -func (v *IngestPackagesResponse) GetIngestPackages() []IngestPackagesIngestPackagesPackage { +func (v *IngestPackagesResponse) GetIngestPackages() []IngestPackagesIngestPackagesPackageIDs { return v.IngestPackages } @@ -25047,19 +24844,10 @@ func IngestLicenses( const IngestPackage_Operation = ` mutation IngestPackage ($pkg: PkgInputSpec!) { ingestPackage(pkg: $pkg) { - ... IdPkgTree - } -} -fragment IdPkgTree on Package { - id - namespaces { - id - names { - id - versions { - id - } - } + packageTypeID + packageNamespaceID + packageNameID + packageVersionID } } ` @@ -25094,19 +24882,10 @@ func IngestPackage( const IngestPackages_Operation = ` mutation IngestPackages ($pkgs: [PkgInputSpec!]!) { ingestPackages(pkgs: $pkgs) { - ... IdPkgTree - } -} -fragment IdPkgTree on Package { - id - namespaces { - id - names { - id - versions { - id - } - } + packageTypeID + packageNamespaceID + packageNameID + packageVersionID } } ` diff --git a/pkg/assembler/clients/helpers/assembler.go b/pkg/assembler/clients/helpers/assembler.go index 19bc973df38..d7666168b9d 100644 --- a/pkg/assembler/clients/helpers/assembler.go +++ b/pkg/assembler/clients/helpers/assembler.go @@ -231,7 +231,7 @@ func ingestPackage(ctx context.Context, client graphql.Client, v *model.PkgInput if result, err := model.IngestPackage(ctx, client, *v); err != nil { return nil, err } else { - return retrievePackageVersionID(&result.IngestPackage) + return &result.IngestPackage.PackageVersionID, nil } } @@ -498,12 +498,4 @@ func validatePackageSourceOrArtifactInput(pkg *model.PkgInputSpec, src *model.So return nil } -func retrievePackageVersionID(pkg *model.IngestPackageIngestPackage) (*string, error) { - if pkg != nil && len(pkg.Namespaces) == 1 && len(pkg.Namespaces[0].Names) == 1 && len(pkg.Namespaces[0].Names[0].Versions) == 1 { - return &pkg.Namespaces[0].Names[0].Versions[0].Id, nil - } else { - return nil, fmt.Errorf("could not identify PackageVersion id from ingested package") - } -} - // TODO(lumjjb): add more ingestion verbs as they come up diff --git a/pkg/assembler/clients/helpers/bulk.go b/pkg/assembler/clients/helpers/bulk.go index ce28f910195..901697e7e51 100644 --- a/pkg/assembler/clients/helpers/bulk.go +++ b/pkg/assembler/clients/helpers/bulk.go @@ -213,7 +213,11 @@ func ingestPackages(ctx context.Context, client graphql.Client, v []model.PkgInp if err != nil { return nil, fmt.Errorf("ingestPackages failed with error: %w", err) } - return retrievePackageVersionIDs(response.IngestPackages) + var results []string + for _, pkg := range response.IngestPackages { + results = append(results, pkg.PackageVersionID) + } + return results, nil } func ingestSources(ctx context.Context, client graphql.Client, v []model.SourceInputSpec) error { @@ -849,15 +853,3 @@ func ingestCertifyLegals(ctx context.Context, client graphql.Client, v []assembl } return nil } - -func retrievePackageVersionIDs(pkgs []model.IngestPackagesIngestPackagesPackage) ([]string, error) { - var results []string - for _, pkg := range pkgs { - if len(pkg.Namespaces) == 1 && len(pkg.Namespaces[0].Names) == 1 && len(pkg.Namespaces[0].Names[0].Versions) == 1 { - results = append(results, pkg.Namespaces[0].Names[0].Versions[0].Id) - } else { - return nil, fmt.Errorf("could not identify PackageVersion id from ingested package") - } - } - return results, nil -} diff --git a/pkg/assembler/clients/operations/package.graphql b/pkg/assembler/clients/operations/package.graphql index e33f490ad97..c475acc6b10 100644 --- a/pkg/assembler/clients/operations/package.graphql +++ b/pkg/assembler/clients/operations/package.graphql @@ -19,7 +19,10 @@ mutation IngestPackage($pkg: PkgInputSpec!) { ingestPackage(pkg: $pkg) { - ...IdPkgTree + packageTypeID + packageNamespaceID + packageNameID + packageVersionID } } @@ -27,7 +30,10 @@ mutation IngestPackage($pkg: PkgInputSpec!) { mutation IngestPackages($pkgs: [PkgInputSpec!]!) { ingestPackages(pkgs: $pkgs) { - ...IdPkgTree + packageTypeID + packageNamespaceID + packageNameID + packageVersionID } } diff --git a/pkg/assembler/clients/operations/trees.graphql b/pkg/assembler/clients/operations/trees.graphql index 0cff4c33434..c9aeba03a33 100644 --- a/pkg/assembler/clients/operations/trees.graphql +++ b/pkg/assembler/clients/operations/trees.graphql @@ -19,19 +19,6 @@ # TODO(mihaimaruseac): Clean this up: do we want All of these to be returned? -fragment IdPkgTree on Package { - id - namespaces { - id - names { - id - versions { - id - } - } - } -} - fragment AllPkgTree on Package { id type diff --git a/pkg/assembler/graphql/generated/artifact.generated.go b/pkg/assembler/graphql/generated/artifact.generated.go index 884bea0380d..5471a1e525a 100644 --- a/pkg/assembler/graphql/generated/artifact.generated.go +++ b/pkg/assembler/graphql/generated/artifact.generated.go @@ -53,8 +53,8 @@ type MutationResolver interface { IngestLicenses(ctx context.Context, licenses []*model.LicenseInputSpec) ([]string, error) IngestHasMetadata(ctx context.Context, subject model.PackageSourceOrArtifactInput, pkgMatchType model.MatchFlags, hasMetadata model.HasMetadataInputSpec) (string, error) IngestBulkHasMetadata(ctx context.Context, subjects model.PackageSourceOrArtifactInputs, pkgMatchType model.MatchFlags, hasMetadataList []*model.HasMetadataInputSpec) ([]string, error) - IngestPackage(ctx context.Context, pkg model.PkgInputSpec) (*model.Package, error) - IngestPackages(ctx context.Context, pkgs []*model.PkgInputSpec) ([]*model.Package, error) + IngestPackage(ctx context.Context, pkg model.PkgInputSpec) (*model.PackageIDs, error) + IngestPackages(ctx context.Context, pkgs []*model.PkgInputSpec) ([]*model.PackageIDs, error) IngestPkgEqual(ctx context.Context, pkg model.PkgInputSpec, otherPackage model.PkgInputSpec, pkgEqual model.PkgEqualInputSpec) (string, error) IngestPkgEquals(ctx context.Context, pkgs []*model.PkgInputSpec, otherPackages []*model.PkgInputSpec, pkgEquals []*model.PkgEqualInputSpec) ([]string, error) IngestSource(ctx context.Context, source model.SourceInputSpec) (string, error) @@ -3946,9 +3946,9 @@ func (ec *executionContext) _Mutation_ingestPackage(ctx context.Context, field g } return graphql.Null } - res := resTmp.(*model.Package) + res := resTmp.(*model.PackageIDs) fc.Result = res - return ec.marshalNPackage2ᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackage(ctx, field.Selections, res) + return ec.marshalNPackageIDs2ᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageIDs(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Mutation_ingestPackage(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -3959,14 +3959,16 @@ func (ec *executionContext) fieldContext_Mutation_ingestPackage(ctx context.Cont IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "id": - return ec.fieldContext_Package_id(ctx, field) - case "type": - return ec.fieldContext_Package_type(ctx, field) - case "namespaces": - return ec.fieldContext_Package_namespaces(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type Package", field.Name) + case "packageTypeID": + return ec.fieldContext_PackageIDs_packageTypeID(ctx, field) + case "packageNamespaceID": + return ec.fieldContext_PackageIDs_packageNamespaceID(ctx, field) + case "packageNameID": + return ec.fieldContext_PackageIDs_packageNameID(ctx, field) + case "packageVersionID": + return ec.fieldContext_PackageIDs_packageVersionID(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PackageIDs", field.Name) }, } defer func() { @@ -4009,9 +4011,9 @@ func (ec *executionContext) _Mutation_ingestPackages(ctx context.Context, field } return graphql.Null } - res := resTmp.([]*model.Package) + res := resTmp.([]*model.PackageIDs) fc.Result = res - return ec.marshalNPackage2ᚕᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageᚄ(ctx, field.Selections, res) + return ec.marshalNPackageIDs2ᚕᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageIDsᚄ(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Mutation_ingestPackages(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -4022,14 +4024,16 @@ func (ec *executionContext) fieldContext_Mutation_ingestPackages(ctx context.Con IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "id": - return ec.fieldContext_Package_id(ctx, field) - case "type": - return ec.fieldContext_Package_type(ctx, field) - case "namespaces": - return ec.fieldContext_Package_namespaces(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type Package", field.Name) + case "packageTypeID": + return ec.fieldContext_PackageIDs_packageTypeID(ctx, field) + case "packageNamespaceID": + return ec.fieldContext_PackageIDs_packageNamespaceID(ctx, field) + case "packageNameID": + return ec.fieldContext_PackageIDs_packageNameID(ctx, field) + case "packageVersionID": + return ec.fieldContext_PackageIDs_packageVersionID(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PackageIDs", field.Name) }, } defer func() { diff --git a/pkg/assembler/graphql/generated/package.generated.go b/pkg/assembler/graphql/generated/package.generated.go index 03edd42b45d..ebe921c80b4 100644 --- a/pkg/assembler/graphql/generated/package.generated.go +++ b/pkg/assembler/graphql/generated/package.generated.go @@ -169,6 +169,182 @@ func (ec *executionContext) fieldContext_Package_namespaces(ctx context.Context, return fc, nil } +func (ec *executionContext) _PackageIDs_packageTypeID(ctx context.Context, field graphql.CollectedField, obj *model.PackageIDs) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PackageIDs_packageTypeID(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PackageTypeID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PackageIDs_packageTypeID(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PackageIDs", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PackageIDs_packageNamespaceID(ctx context.Context, field graphql.CollectedField, obj *model.PackageIDs) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PackageIDs_packageNamespaceID(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PackageNamespaceID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PackageIDs_packageNamespaceID(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PackageIDs", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PackageIDs_packageNameID(ctx context.Context, field graphql.CollectedField, obj *model.PackageIDs) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PackageIDs_packageNameID(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PackageNameID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PackageIDs_packageNameID(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PackageIDs", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PackageIDs_packageVersionID(ctx context.Context, field graphql.CollectedField, obj *model.PackageIDs) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PackageIDs_packageVersionID(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PackageVersionID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PackageIDs_packageVersionID(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PackageIDs", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _PackageName_id(ctx context.Context, field graphql.CollectedField, obj *model.PackageName) (ret graphql.Marshaler) { fc, err := ec.fieldContext_PackageName_id(ctx, field) if err != nil { @@ -1044,6 +1220,60 @@ func (ec *executionContext) _Package(ctx context.Context, sel ast.SelectionSet, return out } +var packageIDsImplementors = []string{"PackageIDs"} + +func (ec *executionContext) _PackageIDs(ctx context.Context, sel ast.SelectionSet, obj *model.PackageIDs) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, packageIDsImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("PackageIDs") + case "packageTypeID": + out.Values[i] = ec._PackageIDs_packageTypeID(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "packageNamespaceID": + out.Values[i] = ec._PackageIDs_packageNamespaceID(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "packageNameID": + out.Values[i] = ec._PackageIDs_packageNameID(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "packageVersionID": + out.Values[i] = ec._PackageIDs_packageVersionID(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var packageNameImplementors = []string{"PackageName"} func (ec *executionContext) _PackageName(ctx context.Context, sel ast.SelectionSet, obj *model.PackageName) graphql.Marshaler { @@ -1244,10 +1474,6 @@ func (ec *executionContext) _PackageVersion(ctx context.Context, sel ast.Selecti // region ***************************** type.gotpl ***************************** -func (ec *executionContext) marshalNPackage2githubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackage(ctx context.Context, sel ast.SelectionSet, v model.Package) graphql.Marshaler { - return ec._Package(ctx, sel, &v) -} - func (ec *executionContext) marshalNPackage2ᚕᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Package) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -1302,6 +1528,64 @@ func (ec *executionContext) marshalNPackage2ᚖgithubᚗcomᚋguacsecᚋguacᚋp return ec._Package(ctx, sel, v) } +func (ec *executionContext) marshalNPackageIDs2githubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageIDs(ctx context.Context, sel ast.SelectionSet, v model.PackageIDs) graphql.Marshaler { + return ec._PackageIDs(ctx, sel, &v) +} + +func (ec *executionContext) marshalNPackageIDs2ᚕᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageIDsᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.PackageIDs) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNPackageIDs2ᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageIDs(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNPackageIDs2ᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageIDs(ctx context.Context, sel ast.SelectionSet, v *model.PackageIDs) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._PackageIDs(ctx, sel, v) +} + func (ec *executionContext) marshalNPackageName2ᚕᚖgithubᚗcomᚋguacsecᚋguacᚋpkgᚋassemblerᚋgraphqlᚋmodelᚐPackageNameᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.PackageName) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup diff --git a/pkg/assembler/graphql/generated/root_.generated.go b/pkg/assembler/graphql/generated/root_.generated.go index ff426031332..a156e90c130 100644 --- a/pkg/assembler/graphql/generated/root_.generated.go +++ b/pkg/assembler/graphql/generated/root_.generated.go @@ -240,6 +240,13 @@ type ComplexityRoot struct { Type func(childComplexity int) int } + PackageIDs struct { + PackageNameID func(childComplexity int) int + PackageNamespaceID func(childComplexity int) int + PackageTypeID func(childComplexity int) int + PackageVersionID func(childComplexity int) int + } + PackageName struct { ID func(childComplexity int) int Name func(childComplexity int) int @@ -1679,6 +1686,34 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Package.Type(childComplexity), true + case "PackageIDs.packageNameID": + if e.complexity.PackageIDs.PackageNameID == nil { + break + } + + return e.complexity.PackageIDs.PackageNameID(childComplexity), true + + case "PackageIDs.packageNamespaceID": + if e.complexity.PackageIDs.PackageNamespaceID == nil { + break + } + + return e.complexity.PackageIDs.PackageNamespaceID(childComplexity), true + + case "PackageIDs.packageTypeID": + if e.complexity.PackageIDs.PackageTypeID == nil { + break + } + + return e.complexity.PackageIDs.PackageTypeID(childComplexity), true + + case "PackageIDs.packageVersionID": + if e.complexity.PackageIDs.PackageVersionID == nil { + break + } + + return e.complexity.PackageIDs.PackageVersionID(childComplexity), true + case "PackageName.id": if e.complexity.PackageName.ID == nil { break @@ -4699,9 +4734,19 @@ extend type Query { extend type Mutation { "Ingests a new package and returns a corresponding package hierarchy containing only the IDs. The returned ID can be empty string." - ingestPackage(pkg: PkgInputSpec!): Package! + ingestPackage(pkg: PkgInputSpec!): PackageIDs! "Bulk ingests packages and returns the list of corresponding package hierarchies containing only the IDs. The returned array of IDs can be empty strings." - ingestPackages(pkgs: [PkgInputSpec!]!): [Package!]! + ingestPackages(pkgs: [PkgInputSpec!]!): [PackageIDs!]! +} + +""" +The IDs of the ingested package +""" +type PackageIDs { + packageTypeID: ID! + packageNamespaceID: ID! + packageNameID: ID! + packageVersionID: ID! } `, BuiltIn: false}, {Name: "../schema/path.graphql", Input: `# diff --git a/pkg/assembler/graphql/helpers/package.go b/pkg/assembler/graphql/helpers/package.go index 785ed2f7b02..2e729d7b148 100644 --- a/pkg/assembler/graphql/helpers/package.go +++ b/pkg/assembler/graphql/helpers/package.go @@ -20,23 +20,23 @@ import ( ) // Return a package structure containing only IDs -func GetPackageAsIds(packages []*model.Package) []*model.Package { - results := []*model.Package{} +func GetPackageAsIds(packages []*model.Package) []*model.PackageIDs { + results := []*model.PackageIDs{} for _, pkg := range packages { - result := &model.Package{ID: pkg.ID} + resultPackage := model.PackageIDs{PackageTypeID: pkg.ID} for _, namespace := range pkg.Namespaces { - resultNamespace := &model.PackageNamespace{ID: namespace.ID} + resultNamespace := resultPackage + resultNamespace.PackageNamespaceID = namespace.ID for _, name := range namespace.Names { - resultName := &model.PackageName{ID: name.ID} + resultName := resultNamespace + resultName.PackageNameID = name.Name for _, version := range name.Versions { - resultVersion := &model.PackageVersion{ID: version.ID} - resultName.Versions = append(resultName.Versions, resultVersion) + resultVersion := resultName + resultVersion.PackageVersionID = version.ID + results = append(results, &resultVersion) } - resultNamespace.Names = append(resultNamespace.Names, resultName) } - result.Namespaces = append(result.Namespaces, resultNamespace) } - results = append(results, result) } return results } diff --git a/pkg/assembler/graphql/model/nodes.go b/pkg/assembler/graphql/model/nodes.go index 5e6c2ff1f54..42465f521c4 100644 --- a/pkg/assembler/graphql/model/nodes.go +++ b/pkg/assembler/graphql/model/nodes.go @@ -764,6 +764,14 @@ func (Package) IsPackageOrSource() {} func (Package) IsNode() {} +// The IDs of the ingested package +type PackageIDs struct { + PackageTypeID string `json:"packageTypeID"` + PackageNamespaceID string `json:"packageNamespaceID"` + PackageNameID string `json:"packageNameID"` + PackageVersionID string `json:"packageVersionID"` +} + // PackageName is a name for packages. // // In the pURL representation, each PackageName matches the diff --git a/pkg/assembler/graphql/resolvers/package.resolvers.go b/pkg/assembler/graphql/resolvers/package.resolvers.go index 0f7a237771b..d8840fbfed0 100644 --- a/pkg/assembler/graphql/resolvers/package.resolvers.go +++ b/pkg/assembler/graphql/resolvers/package.resolvers.go @@ -13,7 +13,7 @@ import ( ) // IngestPackage is the resolver for the ingestPackage field. -func (r *mutationResolver) IngestPackage(ctx context.Context, pkg model.PkgInputSpec) (*model.Package, error) { +func (r *mutationResolver) IngestPackage(ctx context.Context, pkg model.PkgInputSpec) (*model.PackageIDs, error) { // Return the id of the PackageVersion which has been ingested // TODO (knrc) - check why this was originally returning the ID for the Package, since that is not specific enough @@ -29,7 +29,7 @@ func (r *mutationResolver) IngestPackage(ctx context.Context, pkg model.PkgInput } // IngestPackages is the resolver for the ingestPackages field. -func (r *mutationResolver) IngestPackages(ctx context.Context, pkgs []*model.PkgInputSpec) ([]*model.Package, error) { +func (r *mutationResolver) IngestPackages(ctx context.Context, pkgs []*model.PkgInputSpec) ([]*model.PackageIDs, error) { ingestedPackages, err := r.Backend.IngestPackages(ctx, pkgs) if err == nil { results := helpers.GetPackageAsIds(ingestedPackages) diff --git a/pkg/assembler/graphql/schema/package.graphql b/pkg/assembler/graphql/schema/package.graphql index 54fcbf31c5c..fe4cf80f66f 100644 --- a/pkg/assembler/graphql/schema/package.graphql +++ b/pkg/assembler/graphql/schema/package.graphql @@ -182,7 +182,17 @@ extend type Query { extend type Mutation { "Ingests a new package and returns a corresponding package hierarchy containing only the IDs. The returned ID can be empty string." - ingestPackage(pkg: PkgInputSpec!): Package! + ingestPackage(pkg: PkgInputSpec!): PackageIDs! "Bulk ingests packages and returns the list of corresponding package hierarchies containing only the IDs. The returned array of IDs can be empty strings." - ingestPackages(pkgs: [PkgInputSpec!]!): [Package!]! + ingestPackages(pkgs: [PkgInputSpec!]!): [PackageIDs!]! +} + +""" +The IDs of the ingested package +""" +type PackageIDs { + packageTypeID: ID! + packageNamespaceID: ID! + packageNameID: ID! + packageVersionID: ID! }