Refactor create vendor mutation to use connection update

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-19 10:37:55 +01:00
parent bb85434340
commit d9c76878c0
8 changed files with 598 additions and 295 deletions

View File

@@ -5,6 +5,7 @@ import {
usePreloadedQuery, usePreloadedQuery,
useQueryLoader, useQueryLoader,
useMutation, useMutation,
ConnectionHandler,
} from "react-relay"; } from "react-relay";
import { useSearchParams } from "react-router"; import { useSearchParams } from "react-router";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
@@ -16,6 +17,10 @@ import { Link } from "react-router";
import Fuse from "fuse.js"; import Fuse from "fuse.js";
import type { VendorListPageQuery as VendorListPageQueryType } from "./__generated__/VendorListPageQuery.graphql"; import type { VendorListPageQuery as VendorListPageQueryType } from "./__generated__/VendorListPageQuery.graphql";
import { Helmet } from "react-helmet-async"; import { Helmet } from "react-helmet-async";
import { VendorListPageCreateVendorMutation } from "./__generated__/VendorListPageCreateVendorMutation.graphql";
import { VendorListPageDeleteVendorMutation } from "./__generated__/VendorListPageDeleteVendorMutation.graphql";
import { toast } from "@/hooks/use-toast";
const ITEMS_PER_PAGE = 20; const ITEMS_PER_PAGE = 20;
const vendorListPageQuery = graphql` const vendorListPageQuery = graphql`
@@ -25,10 +30,11 @@ const vendorListPageQuery = graphql`
$last: Int $last: Int
$before: CursorKey $before: CursorKey
) { ) {
node(id: "AZSfP_xAcAC5IAAAAAAltA") { currentOrganization: node(id: "AZSfP_xAcAC5IAAAAAAltA") {
id id
... on Organization { ... on Organization {
vendors(first: $first, after: $after, last: $last, before: $before) { vendors(first: $first, after: $after, last: $last, before: $before)
@connection(key: "VendorListPageQuery_vendors") {
edges { edges {
node { node {
id id
@@ -51,14 +57,18 @@ const vendorListPageQuery = graphql`
`; `;
const createVendorMutation = graphql` const createVendorMutation = graphql`
mutation VendorListPageCreateVendorMutation($input: CreateVendorInput!) { mutation VendorListPageCreateVendorMutation($input: CreateVendorInput!, $connections: [ID!]!) {
createVendor(input: $input) { createVendor(input: $input) {
vendorEdge @prependEdge(connections: $connections) {
node {
id id
name name
createdAt createdAt
updatedAt updatedAt
} }
} }
}
}
`; `;
const deleteVendorMutation = graphql` const deleteVendorMutation = graphql`
@@ -92,14 +102,9 @@ const vendorsList = [
{ id: "17", name: "CircleCI", createdAt: new Date().toISOString() }, { id: "17", name: "CircleCI", createdAt: new Date().toISOString() },
]; ];
type LoadQueryType = ReturnType<
typeof useQueryLoader<VendorListPageQueryType>
>[1];
function VendorListContent({ function VendorListContent({
queryRef, queryRef,
onPageChange, onPageChange,
loadQuery,
}: { }: {
queryRef: PreloadedQuery<VendorListPageQueryType>; queryRef: PreloadedQuery<VendorListPageQueryType>;
onPageChange: (params: { onPageChange: (params: {
@@ -108,18 +113,17 @@ function VendorListContent({
last?: number; last?: number;
before?: string; before?: string;
}) => void; }) => void;
loadQuery: LoadQueryType;
}) { }) {
const data = usePreloadedQuery(vendorListPageQuery, queryRef); const data = usePreloadedQuery(vendorListPageQuery, queryRef);
const [searchParams, setSearchParams] = useSearchParams(); const [searchParams, setSearchParams] = useSearchParams();
const [isPending, startTransition] = useTransition(); const [isPending, startTransition] = useTransition();
const [searchTerm, setSearchTerm] = useState(""); const [searchTerm, setSearchTerm] = useState("");
const [filteredVendors, setFilteredVendors] = useState<Array<any>>([]); const [filteredVendors, setFilteredVendors] = useState<Array<any>>([]);
const [createVendor] = useMutation(createVendorMutation); const [createVendor] = useMutation<VendorListPageCreateVendorMutation>(createVendorMutation);
const [deleteVendor] = useMutation(deleteVendorMutation); const [deleteVendor] = useMutation<VendorListPageDeleteVendorMutation>(deleteVendorMutation);
const vendors = data.node?.vendors?.edges?.map((edge) => edge?.node) ?? []; const vendors = data.currentOrganization.vendors?.edges.map((edge) => edge.node) ?? [];
const pageInfo = data.node?.vendors?.pageInfo; const pageInfo = data.currentOrganization.vendors?.pageInfo;
const fuse = new Fuse(vendorsList, { const fuse = new Fuse(vendorsList, {
keys: ["name"], keys: ["name"],
@@ -204,23 +208,23 @@ function VendorListContent({
onClick={() => { onClick={() => {
createVendor({ createVendor({
variables: { variables: {
connections: [ConnectionHandler.getConnectionID(data.currentOrganization.id, "VendorListPageQuery_vendors")],
input: { input: {
organizationId: data.node.id, organizationId: data.currentOrganization.id,
name: vendor.name, name: vendor.name,
description: "",
serviceStartAt: new Date().toISOString(),
serviceCriticality: "LOW",
riskTier: "GENERAL",
}, },
}, },
onCompleted(response: any) { onCompleted(response) {
setSearchTerm(""); setSearchTerm("");
setFilteredVendors([]); setFilteredVendors([]);
loadQuery( toast({
{ title: "Vendor added",
first: ITEMS_PER_PAGE, description: "The vendor has been added successfully",
after: undefined, });
last: undefined,
before: undefined,
},
{ fetchPolicy: "network-only" },
);
}, },
}); });
}} }}
@@ -297,15 +301,10 @@ function VendorListContent({
}, },
}, },
onCompleted() { onCompleted() {
loadQuery( toast({
{ title: "Vendor deleted",
first: ITEMS_PER_PAGE, description: "The vendor has been deleted successfully",
after: undefined, });
last: undefined,
before: undefined,
},
{ fetchPolicy: "network-only" },
);
}, },
}); });
} }
@@ -360,7 +359,6 @@ export default function VendorListPage() {
const [queryRef, loadQuery] = const [queryRef, loadQuery] =
useQueryLoader<VendorListPageQueryType>(vendorListPageQuery); useQueryLoader<VendorListPageQueryType>(vendorListPageQuery);
// Initialize with URL params
useEffect(() => { useEffect(() => {
const after = searchParams.get("after"); const after = searchParams.get("after");
const before = searchParams.get("before"); const before = searchParams.get("before");
@@ -408,7 +406,6 @@ export default function VendorListPage() {
<VendorListContent <VendorListContent
queryRef={queryRef} queryRef={queryRef}
onPageChange={handlePageChange} onPageChange={handlePageChange}
loadQuery={loadQuery}
/> />
</Suspense> </Suspense>
</> </>

View File

@@ -1,5 +1,5 @@
/** /**
* @generated SignedSource<<055f5292e2ca7bfecd0d701ce34c8d34>> * @generated SignedSource<<03e542b8e2ecf3c17be86da4526541d2>>
* @lightSyntaxTransform * @lightSyntaxTransform
* @nogrep * @nogrep
*/ */
@@ -9,48 +9,73 @@
// @ts-nocheck // @ts-nocheck
import { ConcreteRequest } from 'relay-runtime'; import { ConcreteRequest } from 'relay-runtime';
export type RiskTier = "CRITICAL" | "GENERAL" | "SIGNIFICANT";
export type ServiceCriticality = "HIGH" | "LOW" | "MEDIUM";
export type CreateVendorInput = { export type CreateVendorInput = {
description: string; description: string;
name: string; name: string;
organizationId: string; organizationId: string;
privacyPolicyUrl?: string | null | undefined;
riskTier: RiskTier;
serviceCriticality: ServiceCriticality;
serviceStartAt: any;
serviceTerminationAt?: any | null | undefined;
statusPageUrl?: string | null | undefined;
termsOfServiceUrl?: string | null | undefined;
}; };
export type VendorListPageCreateVendorMutation$variables = { export type VendorListPageCreateVendorMutation$variables = {
connections: ReadonlyArray<string>;
input: CreateVendorInput; input: CreateVendorInput;
}; };
export type VendorListPageCreateVendorMutation$data = { export type VendorListPageCreateVendorMutation$data = {
readonly createVendor: { readonly createVendor: {
readonly vendorEdge: {
readonly node: {
readonly createdAt: any; readonly createdAt: any;
readonly id: string; readonly id: string;
readonly name: string; readonly name: string;
readonly updatedAt: any; readonly updatedAt: any;
}; };
}; };
};
};
export type VendorListPageCreateVendorMutation = { export type VendorListPageCreateVendorMutation = {
response: VendorListPageCreateVendorMutation$data; response: VendorListPageCreateVendorMutation$data;
variables: VendorListPageCreateVendorMutation$variables; variables: VendorListPageCreateVendorMutation$variables;
}; };
const node: ConcreteRequest = (function(){ const node: ConcreteRequest = (function(){
var v0 = [ var v0 = {
{ "defaultValue": null,
"kind": "LocalArgument",
"name": "connections"
},
v1 = {
"defaultValue": null, "defaultValue": null,
"kind": "LocalArgument", "kind": "LocalArgument",
"name": "input" "name": "input"
} },
], v2 = [
v1 = [
{
"alias": null,
"args": [
{ {
"kind": "Variable", "kind": "Variable",
"name": "input", "name": "input",
"variableName": "input" "variableName": "input"
} }
], ],
v3 = {
"alias": null,
"args": null,
"concreteType": "VendorEdge",
"kind": "LinkedField",
"name": "vendorEdge",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Vendor", "concreteType": "Vendor",
"kind": "LinkedField", "kind": "LinkedField",
"name": "createVendor", "name": "node",
"plural": false, "plural": false,
"selections": [ "selections": [
{ {
@@ -84,35 +109,85 @@ v1 = [
], ],
"storageKey": null "storageKey": null
} }
]; ],
"storageKey": null
};
return { return {
"fragment": { "fragment": {
"argumentDefinitions": (v0/*: any*/), "argumentDefinitions": [
(v0/*: any*/),
(v1/*: any*/)
],
"kind": "Fragment", "kind": "Fragment",
"metadata": null, "metadata": null,
"name": "VendorListPageCreateVendorMutation", "name": "VendorListPageCreateVendorMutation",
"selections": (v1/*: any*/), "selections": [
{
"alias": null,
"args": (v2/*: any*/),
"concreteType": "CreateVendorPayload",
"kind": "LinkedField",
"name": "createVendor",
"plural": false,
"selections": [
(v3/*: any*/)
],
"storageKey": null
}
],
"type": "Mutation", "type": "Mutation",
"abstractKey": null "abstractKey": null
}, },
"kind": "Request", "kind": "Request",
"operation": { "operation": {
"argumentDefinitions": (v0/*: any*/), "argumentDefinitions": [
(v1/*: any*/),
(v0/*: any*/)
],
"kind": "Operation", "kind": "Operation",
"name": "VendorListPageCreateVendorMutation", "name": "VendorListPageCreateVendorMutation",
"selections": (v1/*: any*/) "selections": [
{
"alias": null,
"args": (v2/*: any*/),
"concreteType": "CreateVendorPayload",
"kind": "LinkedField",
"name": "createVendor",
"plural": false,
"selections": [
(v3/*: any*/),
{
"alias": null,
"args": null,
"filters": null,
"handle": "prependEdge",
"key": "",
"kind": "LinkedHandle",
"name": "vendorEdge",
"handleArgs": [
{
"kind": "Variable",
"name": "connections",
"variableName": "connections"
}
]
}
],
"storageKey": null
}
]
}, },
"params": { "params": {
"cacheID": "11eabcf8c7c1fef7b2cb37bcadf52666", "cacheID": "ddfddd8b4266631b16341e6fe2e04cb5",
"id": null, "id": null,
"metadata": {}, "metadata": {},
"name": "VendorListPageCreateVendorMutation", "name": "VendorListPageCreateVendorMutation",
"operationKind": "mutation", "operationKind": "mutation",
"text": "mutation VendorListPageCreateVendorMutation(\n $input: CreateVendorInput!\n) {\n createVendor(input: $input) {\n id\n name\n createdAt\n updatedAt\n }\n}\n" "text": "mutation VendorListPageCreateVendorMutation(\n $input: CreateVendorInput!\n) {\n createVendor(input: $input) {\n vendorEdge {\n node {\n id\n name\n createdAt\n updatedAt\n }\n }\n }\n}\n"
} }
}; };
})(); })();
(node as any).hash = "aeb5751c0d301a9433e706d237a025cd"; (node as any).hash = "03c48ba8f1db919da507322208e5e136";
export default node; export default node;

View File

@@ -1,5 +1,5 @@
/** /**
* @generated SignedSource<<3b4f62f431760660274bbff4ae888d0a>> * @generated SignedSource<<874e734a238db8fc4ab486da7d49ceee>>
* @lightSyntaxTransform * @lightSyntaxTransform
* @nogrep * @nogrep
*/ */
@@ -16,7 +16,7 @@ export type VendorListPageQuery$variables = {
last?: number | null | undefined; last?: number | null | undefined;
}; };
export type VendorListPageQuery$data = { export type VendorListPageQuery$data = {
readonly node: { readonly currentOrganization: {
readonly id: string; readonly id: string;
readonly vendors?: { readonly vendors?: {
readonly edges: ReadonlyArray<{ readonly edges: ReadonlyArray<{
@@ -78,37 +78,13 @@ v5 = {
"storageKey": null "storageKey": null
}, },
v6 = { v6 = {
"kind": "InlineFragment",
"selections": [
{
"alias": null, "alias": null,
"args": [ "args": null,
{ "kind": "ScalarField",
"kind": "Variable", "name": "__typename",
"name": "after", "storageKey": null
"variableName": "after"
}, },
{ v7 = [
"kind": "Variable",
"name": "before",
"variableName": "before"
},
{
"kind": "Variable",
"name": "first",
"variableName": "first"
},
{
"kind": "Variable",
"name": "last",
"variableName": "last"
}
],
"concreteType": "VendorConnection",
"kind": "LinkedField",
"name": "vendors",
"plural": false,
"selections": [
{ {
"alias": null, "alias": null,
"args": null, "args": null,
@@ -146,7 +122,8 @@ v6 = {
"kind": "ScalarField", "kind": "ScalarField",
"name": "updatedAt", "name": "updatedAt",
"storageKey": null "storageKey": null
} },
(v6/*: any*/)
], ],
"storageKey": null "storageKey": null
}, },
@@ -200,12 +177,28 @@ v6 = {
"storageKey": null "storageKey": null
} }
], ],
"storageKey": null v8 = [
{
"kind": "Variable",
"name": "after",
"variableName": "after"
},
{
"kind": "Variable",
"name": "before",
"variableName": "before"
},
{
"kind": "Variable",
"name": "first",
"variableName": "first"
},
{
"kind": "Variable",
"name": "last",
"variableName": "last"
} }
], ];
"type": "Organization",
"abstractKey": null
};
return { return {
"fragment": { "fragment": {
"argumentDefinitions": [ "argumentDefinitions": [
@@ -219,7 +212,7 @@ return {
"name": "VendorListPageQuery", "name": "VendorListPageQuery",
"selections": [ "selections": [
{ {
"alias": null, "alias": "currentOrganization",
"args": (v4/*: any*/), "args": (v4/*: any*/),
"concreteType": null, "concreteType": null,
"kind": "LinkedField", "kind": "LinkedField",
@@ -227,7 +220,23 @@ return {
"plural": false, "plural": false,
"selections": [ "selections": [
(v5/*: any*/), (v5/*: any*/),
(v6/*: any*/) {
"kind": "InlineFragment",
"selections": [
{
"alias": "vendors",
"args": null,
"concreteType": "VendorConnection",
"kind": "LinkedField",
"name": "__VendorListPageQuery_vendors_connection",
"plural": false,
"selections": (v7/*: any*/),
"storageKey": null
}
],
"type": "Organization",
"abstractKey": null
}
], ],
"storageKey": "node(id:\"AZSfP_xAcAC5IAAAAAAltA\")" "storageKey": "node(id:\"AZSfP_xAcAC5IAAAAAAltA\")"
} }
@@ -247,38 +256,69 @@ return {
"name": "VendorListPageQuery", "name": "VendorListPageQuery",
"selections": [ "selections": [
{ {
"alias": null, "alias": "currentOrganization",
"args": (v4/*: any*/), "args": (v4/*: any*/),
"concreteType": null, "concreteType": null,
"kind": "LinkedField", "kind": "LinkedField",
"name": "node", "name": "node",
"plural": false, "plural": false,
"selections": [
(v6/*: any*/),
(v5/*: any*/),
{
"kind": "InlineFragment",
"selections": [ "selections": [
{ {
"alias": null, "alias": null,
"args": null, "args": (v8/*: any*/),
"kind": "ScalarField", "concreteType": "VendorConnection",
"name": "__typename", "kind": "LinkedField",
"name": "vendors",
"plural": false,
"selections": (v7/*: any*/),
"storageKey": null "storageKey": null
}, },
(v5/*: any*/), {
(v6/*: any*/) "alias": null,
"args": (v8/*: any*/),
"filters": null,
"handle": "connection",
"key": "VendorListPageQuery_vendors",
"kind": "LinkedHandle",
"name": "vendors"
}
],
"type": "Organization",
"abstractKey": null
}
], ],
"storageKey": "node(id:\"AZSfP_xAcAC5IAAAAAAltA\")" "storageKey": "node(id:\"AZSfP_xAcAC5IAAAAAAltA\")"
} }
] ]
}, },
"params": { "params": {
"cacheID": "d38a5cbe98c811f237ea5722871aabf6", "cacheID": "079490495e96d3609a263570f185673b",
"id": null, "id": null,
"metadata": {}, "metadata": {
"connection": [
{
"count": null,
"cursor": null,
"direction": "bidirectional",
"path": [
"currentOrganization",
"vendors"
]
}
]
},
"name": "VendorListPageQuery", "name": "VendorListPageQuery",
"operationKind": "query", "operationKind": "query",
"text": "query VendorListPageQuery(\n $first: Int\n $after: CursorKey\n $last: Int\n $before: CursorKey\n) {\n node(id: \"AZSfP_xAcAC5IAAAAAAltA\") {\n __typename\n id\n ... on Organization {\n vendors(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n }\n cursor\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n}\n" "text": "query VendorListPageQuery(\n $first: Int\n $after: CursorKey\n $last: Int\n $before: CursorKey\n) {\n currentOrganization: node(id: \"AZSfP_xAcAC5IAAAAAAltA\") {\n __typename\n id\n ... on Organization {\n vendors(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n}\n"
} }
}; };
})(); })();
(node as any).hash = "e371fe8685ccc70b229f0d5b07d6e271"; (node as any).hash = "9613eb9b1e34b2ebffda69c5909f5f5b";
export default node; export default node;

View File

@@ -314,7 +314,7 @@ type Query {
} }
type Mutation { type Mutation {
createVendor(input: CreateVendorInput!): Vendor! createVendor(input: CreateVendorInput!): CreateVendorPayload!
updateVendor(input: UpdateVendorInput!): Vendor! updateVendor(input: UpdateVendorInput!): Vendor!
deleteVendor(input: DeleteVendorInput!): Void! deleteVendor(input: DeleteVendorInput!): Void!
createPeople(input: CreatePeopleInput!): CreatePeoplePayload! createPeople(input: CreatePeopleInput!): CreatePeoplePayload!
@@ -326,6 +326,13 @@ input CreateVendorInput {
organizationId: ID! organizationId: ID!
name: String! name: String!
description: String! description: String!
serviceStartAt: Datetime!
serviceTerminationAt: Datetime
serviceCriticality: ServiceCriticality!
riskTier: RiskTier!
statusPageUrl: String
termsOfServiceUrl: String
privacyPolicyUrl: String
} }
input DeleteVendorInput { input DeleteVendorInput {
@@ -382,3 +389,7 @@ input UpdateVendorInput {
type CreatePeoplePayload { type CreatePeoplePayload {
peopleEdge: PeopleEdge! peopleEdge: PeopleEdge!
} }
type CreateVendorPayload {
vendorEdge: VendorEdge!
}

View File

@@ -100,6 +100,10 @@ type ComplexityRoot struct {
PeopleEdge func(childComplexity int) int PeopleEdge func(childComplexity int) int
} }
CreateVendorPayload struct {
VendorEdge func(childComplexity int) int
}
Evidence struct { Evidence struct {
CreatedAt func(childComplexity int) int CreatedAt func(childComplexity int) int
FileURL func(childComplexity int) int FileURL func(childComplexity int) int
@@ -289,7 +293,7 @@ type FrameworkResolver interface {
Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlConnection, error) Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlConnection, error)
} }
type MutationResolver interface { type MutationResolver interface {
CreateVendor(ctx context.Context, input types.CreateVendorInput) (*types.Vendor, error) CreateVendor(ctx context.Context, input types.CreateVendorInput) (*types.CreateVendorPayload, error)
UpdateVendor(ctx context.Context, input types.UpdateVendorInput) (*types.Vendor, error) UpdateVendor(ctx context.Context, input types.UpdateVendorInput) (*types.Vendor, error)
DeleteVendor(ctx context.Context, input types.DeleteVendorInput) (string, error) DeleteVendor(ctx context.Context, input types.DeleteVendorInput) (string, error)
CreatePeople(ctx context.Context, input types.CreatePeopleInput) (*types.CreatePeoplePayload, error) CreatePeople(ctx context.Context, input types.CreatePeopleInput) (*types.CreatePeoplePayload, error)
@@ -506,6 +510,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.CreatePeoplePayload.PeopleEdge(childComplexity), true return e.complexity.CreatePeoplePayload.PeopleEdge(childComplexity), true
case "CreateVendorPayload.vendorEdge":
if e.complexity.CreateVendorPayload.VendorEdge == nil {
break
}
return e.complexity.CreateVendorPayload.VendorEdge(childComplexity), true
case "Evidence.createdAt": case "Evidence.createdAt":
if e.complexity.Evidence.CreatedAt == nil { if e.complexity.Evidence.CreatedAt == nil {
break break
@@ -1717,7 +1728,7 @@ type Query {
} }
type Mutation { type Mutation {
createVendor(input: CreateVendorInput!): Vendor! createVendor(input: CreateVendorInput!): CreateVendorPayload!
updateVendor(input: UpdateVendorInput!): Vendor! updateVendor(input: UpdateVendorInput!): Vendor!
deleteVendor(input: DeleteVendorInput!): Void! deleteVendor(input: DeleteVendorInput!): Void!
createPeople(input: CreatePeopleInput!): CreatePeoplePayload! createPeople(input: CreatePeopleInput!): CreatePeoplePayload!
@@ -1729,6 +1740,13 @@ input CreateVendorInput {
organizationId: ID! organizationId: ID!
name: String! name: String!
description: String! description: String!
serviceStartAt: Datetime!
serviceTerminationAt: Datetime
serviceCriticality: ServiceCriticality!
riskTier: RiskTier!
statusPageUrl: String
termsOfServiceUrl: String
privacyPolicyUrl: String
} }
input DeleteVendorInput { input DeleteVendorInput {
@@ -1784,6 +1802,10 @@ input UpdateVendorInput {
type CreatePeoplePayload { type CreatePeoplePayload {
peopleEdge: PeopleEdge! peopleEdge: PeopleEdge!
}
type CreateVendorPayload {
vendorEdge: VendorEdge!
}`, BuiltIn: false}, }`, BuiltIn: false},
} }
var parsedSchema = gqlparser.MustLoadSchema(sources...) var parsedSchema = gqlparser.MustLoadSchema(sources...)
@@ -3723,6 +3745,50 @@ func (ec *executionContext) fieldContext_CreatePeoplePayload_peopleEdge(_ contex
return fc, nil return fc, nil
} }
func (ec *executionContext) _CreateVendorPayload_vendorEdge(ctx context.Context, field graphql.CollectedField, obj *types.CreateVendorPayload) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_CreateVendorPayload_vendorEdge(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return obj.VendorEdge, 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.(*types.VendorEdge)
fc.Result = res
return ec.marshalNVendorEdge2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐVendorEdge(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_CreateVendorPayload_vendorEdge(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "CreateVendorPayload",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
switch field.Name {
case "cursor":
return ec.fieldContext_VendorEdge_cursor(ctx, field)
case "node":
return ec.fieldContext_VendorEdge_node(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type VendorEdge", field.Name)
},
}
return fc, nil
}
func (ec *executionContext) _Evidence_id(ctx context.Context, field graphql.CollectedField, obj *types.Evidence) (ret graphql.Marshaler) { func (ec *executionContext) _Evidence_id(ctx context.Context, field graphql.CollectedField, obj *types.Evidence) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Evidence_id(ctx, field) fc, err := ec.fieldContext_Evidence_id(ctx, field)
if err != nil { if err != nil {
@@ -5069,9 +5135,9 @@ func (ec *executionContext) _Mutation_createVendor(ctx context.Context, field gr
} }
return graphql.Null return graphql.Null
} }
res := resTmp.(*types.Vendor) res := resTmp.(*types.CreateVendorPayload)
fc.Result = res fc.Result = res
return ec.marshalNVendor2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐVendor(ctx, field.Selections, res) return ec.marshalNCreateVendorPayload2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐCreateVendorPayload(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Mutation_createVendor(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Mutation_createVendor(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -5082,34 +5148,10 @@ func (ec *executionContext) fieldContext_Mutation_createVendor(ctx context.Conte
IsResolver: true, IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
switch field.Name { switch field.Name {
case "id": case "vendorEdge":
return ec.fieldContext_Vendor_id(ctx, field) return ec.fieldContext_CreateVendorPayload_vendorEdge(ctx, field)
case "name":
return ec.fieldContext_Vendor_name(ctx, field)
case "description":
return ec.fieldContext_Vendor_description(ctx, field)
case "serviceStartAt":
return ec.fieldContext_Vendor_serviceStartAt(ctx, field)
case "serviceTerminationAt":
return ec.fieldContext_Vendor_serviceTerminationAt(ctx, field)
case "serviceCriticality":
return ec.fieldContext_Vendor_serviceCriticality(ctx, field)
case "riskTier":
return ec.fieldContext_Vendor_riskTier(ctx, field)
case "statusPageUrl":
return ec.fieldContext_Vendor_statusPageUrl(ctx, field)
case "termsOfServiceUrl":
return ec.fieldContext_Vendor_termsOfServiceUrl(ctx, field)
case "privacyPolicyUrl":
return ec.fieldContext_Vendor_privacyPolicyUrl(ctx, field)
case "createdAt":
return ec.fieldContext_Vendor_createdAt(ctx, field)
case "updatedAt":
return ec.fieldContext_Vendor_updatedAt(ctx, field)
case "version":
return ec.fieldContext_Vendor_version(ctx, field)
} }
return nil, fmt.Errorf("no field named %q was found under type Vendor", field.Name) return nil, fmt.Errorf("no field named %q was found under type CreateVendorPayload", field.Name)
}, },
} }
ctx = graphql.WithFieldContext(ctx, fc) ctx = graphql.WithFieldContext(ctx, fc)
@@ -9719,7 +9761,7 @@ func (ec *executionContext) unmarshalInputCreateVendorInput(ctx context.Context,
asMap[k] = v asMap[k] = v
} }
fieldsInOrder := [...]string{"organizationId", "name", "description"} fieldsInOrder := [...]string{"organizationId", "name", "description", "serviceStartAt", "serviceTerminationAt", "serviceCriticality", "riskTier", "statusPageUrl", "termsOfServiceUrl", "privacyPolicyUrl"}
for _, k := range fieldsInOrder { for _, k := range fieldsInOrder {
v, ok := asMap[k] v, ok := asMap[k]
if !ok { if !ok {
@@ -9747,6 +9789,55 @@ func (ec *executionContext) unmarshalInputCreateVendorInput(ctx context.Context,
return it, err return it, err
} }
it.Description = data it.Description = data
case "serviceStartAt":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("serviceStartAt"))
data, err := ec.unmarshalNDatetime2timeᚐTime(ctx, v)
if err != nil {
return it, err
}
it.ServiceStartAt = data
case "serviceTerminationAt":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("serviceTerminationAt"))
data, err := ec.unmarshalODatetime2ᚖtimeᚐTime(ctx, v)
if err != nil {
return it, err
}
it.ServiceTerminationAt = data
case "serviceCriticality":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("serviceCriticality"))
data, err := ec.unmarshalNServiceCriticality2githubᚗcomᚋgetproboᚋproboᚋpkgᚋproboᚋcoredataᚐServiceCriticality(ctx, v)
if err != nil {
return it, err
}
it.ServiceCriticality = data
case "riskTier":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("riskTier"))
data, err := ec.unmarshalNRiskTier2githubᚗcomᚋgetproboᚋproboᚋpkgᚋproboᚋcoredataᚐRiskTier(ctx, v)
if err != nil {
return it, err
}
it.RiskTier = data
case "statusPageUrl":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("statusPageUrl"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.StatusPageURL = data
case "termsOfServiceUrl":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("termsOfServiceUrl"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.TermsOfServiceURL = data
case "privacyPolicyUrl":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("privacyPolicyUrl"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.PrivacyPolicyURL = data
} }
} }
@@ -10436,6 +10527,45 @@ func (ec *executionContext) _CreatePeoplePayload(ctx context.Context, sel ast.Se
return out return out
} }
var createVendorPayloadImplementors = []string{"CreateVendorPayload"}
func (ec *executionContext) _CreateVendorPayload(ctx context.Context, sel ast.SelectionSet, obj *types.CreateVendorPayload) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, createVendorPayloadImplementors)
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("CreateVendorPayload")
case "vendorEdge":
out.Values[i] = ec._CreateVendorPayload_vendorEdge(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 evidenceImplementors = []string{"Evidence", "Node"} var evidenceImplementors = []string{"Evidence", "Node"}
func (ec *executionContext) _Evidence(ctx context.Context, sel ast.SelectionSet, obj *types.Evidence) graphql.Marshaler { func (ec *executionContext) _Evidence(ctx context.Context, sel ast.SelectionSet, obj *types.Evidence) graphql.Marshaler {
@@ -12536,6 +12666,20 @@ func (ec *executionContext) unmarshalNCreateVendorInput2githubᚗcomᚋgetprobo
return res, graphql.ErrorOnPath(ctx, err) return res, graphql.ErrorOnPath(ctx, err)
} }
func (ec *executionContext) marshalNCreateVendorPayload2githubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐCreateVendorPayload(ctx context.Context, sel ast.SelectionSet, v types.CreateVendorPayload) graphql.Marshaler {
return ec._CreateVendorPayload(ctx, sel, &v)
}
func (ec *executionContext) marshalNCreateVendorPayload2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐCreateVendorPayload(ctx context.Context, sel ast.SelectionSet, v *types.CreateVendorPayload) 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._CreateVendorPayload(ctx, sel, v)
}
func (ec *executionContext) unmarshalNCursorKey2githubᚗcomᚋgetproboᚋproboᚋpkgᚋpageᚐCursorKey(ctx context.Context, v any) (page.CursorKey, error) { func (ec *executionContext) unmarshalNCursorKey2githubᚗcomᚋgetproboᚋproboᚋpkgᚋpageᚐCursorKey(ctx context.Context, v any) (page.CursorKey, error) {
res, err := types.UnmarshalCursorKeyScalar(v) res, err := types.UnmarshalCursorKeyScalar(v)
return res, graphql.ErrorOnPath(ctx, err) return res, graphql.ErrorOnPath(ctx, err)

View File

@@ -75,6 +75,17 @@ type CreateVendorInput struct {
OrganizationID gid.GID `json:"organizationId"` OrganizationID gid.GID `json:"organizationId"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
ServiceStartAt time.Time `json:"serviceStartAt"`
ServiceTerminationAt *time.Time `json:"serviceTerminationAt,omitempty"`
ServiceCriticality coredata.ServiceCriticality `json:"serviceCriticality"`
RiskTier coredata.RiskTier `json:"riskTier"`
StatusPageURL *string `json:"statusPageUrl,omitempty"`
TermsOfServiceURL *string `json:"termsOfServiceUrl,omitempty"`
PrivacyPolicyURL *string `json:"privacyPolicyUrl,omitempty"`
}
type CreateVendorPayload struct {
VendorEdge *VendorEdge `json:"vendorEdge"`
} }
type DeletePeopleInput struct { type DeletePeopleInput struct {

View File

@@ -66,16 +66,25 @@ func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework,
} }
// CreateVendor is the resolver for the createVendor field. // CreateVendor is the resolver for the createVendor field.
func (r *mutationResolver) CreateVendor(ctx context.Context, input types.CreateVendorInput) (*types.Vendor, error) { func (r *mutationResolver) CreateVendor(ctx context.Context, input types.CreateVendorInput) (*types.CreateVendorPayload, error) {
vendor, err := r.svc.CreateVendor(ctx, probo.CreateVendorRequest{ vendor, err := r.svc.CreateVendor(ctx, probo.CreateVendorRequest{
OrganizationID: input.OrganizationID, OrganizationID: input.OrganizationID,
Name: input.Name, Name: input.Name,
Description: input.Description,
ServiceStartAt: input.ServiceStartAt,
ServiceTerminationAt: input.ServiceTerminationAt,
ServiceCriticality: input.ServiceCriticality,
RiskTier: input.RiskTier,
StatusPageURL: input.StatusPageURL,
TermsOfServiceURL: input.TermsOfServiceURL,
PrivacyPolicyURL: input.PrivacyPolicyURL,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot create vendor: %w", err) return nil, fmt.Errorf("cannot create vendor: %w", err)
} }
return &types.CreateVendorPayload{
return types.NewVendor(vendor), nil VendorEdge: types.NewVendorEdge(vendor),
}, nil
} }
// UpdateVendor is the resolver for the updateVendor field. // UpdateVendor is the resolver for the updateVendor field.

View File

@@ -28,6 +28,14 @@ type (
CreateVendorRequest struct { CreateVendorRequest struct {
OrganizationID gid.GID OrganizationID gid.GID
Name string Name string
Description string
ServiceStartAt time.Time
ServiceTerminationAt *time.Time
ServiceCriticality coredata.ServiceCriticality
RiskTier coredata.RiskTier
StatusPageURL *string
TermsOfServiceURL *string
PrivacyPolicyURL *string
} }
) )
@@ -48,6 +56,14 @@ func (s Service) CreateVendor(
Name: req.Name, Name: req.Name,
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
Description: req.Description,
ServiceStartAt: req.ServiceStartAt,
ServiceTerminationAt: req.ServiceTerminationAt,
ServiceCriticality: req.ServiceCriticality,
RiskTier: req.RiskTier,
StatusPageURL: req.StatusPageURL,
TermsOfServiceURL: req.TermsOfServiceURL,
PrivacyPolicyURL: req.PrivacyPolicyURL,
} }
err = s.pg.WithTx( err = s.pg.WithTx(