Skip to content

Commit

Permalink
added filtering by name to zones and labels (#368)
Browse files Browse the repository at this point in the history
* added filtering by name to zones and labels

* lint error fix

* lint error fix

* lint error fix

---------

Co-authored-by: PeterL <[email protected]>
  • Loading branch information
plehocky and Skyedown authored Sep 18, 2023
1 parent dc4aa1d commit 4afea05
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/schema/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ input FilterEventHandlerInput {
name: String
}

input FilterLabelsInput {
name: String!
}

input FilterPollDataInput {
afterDate: String
beforeDate: String
Expand All @@ -620,6 +624,10 @@ input FilterWorkflowsInput {
labels: [String!]
}

input FilterZonesInput {
name: String!
}

input FreeResourceInput {
poolId: String!
resource: Record!
Expand Down Expand Up @@ -922,7 +930,7 @@ type Query {
searchQuery: ExecutedWorkflowSearchInput
): ExecutedWorkflowConnection
externalStorage(path: String!): ExternaStorage
labels(after: String, before: String, first: Int, last: Int): LabelConnection!
labels(after: String, before: String, filter: FilterLabelsInput, first: Int, last: Int): LabelConnection!
locations(after: String, before: String, first: Int, last: Int): LocationConnection!
netTopology: NetTopology
node(id: ID!, version: Int): Node
Expand Down Expand Up @@ -968,7 +976,7 @@ type Query {
last: Int
orderBy: WorkflowsOrderByInput
): WorkflowConnection!
zones(after: String, before: String, first: Int, last: Int): ZonesConnection!
zones(after: String, before: String, filter: FilterZonesInput, first: Int, last: Int): ZonesConnection!
}

"""
Expand Down
12 changes: 10 additions & 2 deletions src/schema/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ export const LabelConnection = objectType({
},
});

export const FilterLabelsInput = inputObjectType({
name: 'FilterLabelsInput',
definition: (t) => {
t.nonNull.string('name');
},
});

export const LabelsQuery = extendType({
type: 'Query',
definition: (t) => {
t.nonNull.field('labels', {
type: LabelConnection,
args: PaginationConnectionArgs,
args: { ...PaginationConnectionArgs, filter: FilterLabelsInput },
resolve: async (_, args, { prisma, tenantId }) => {
const baseArgs = { where: { tenantId } };
const { filter } = args;
const baseArgs = { where: { tenantId, ...(filter?.name ? filter : {}) } };
const result = await findManyCursorConnection(
(paginationArgs) => prisma.label.findMany({ ...baseArgs, ...paginationArgs }),
() => prisma.label.count(baseArgs),
Expand Down
10 changes: 10 additions & 0 deletions src/schema/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ export interface NexusGenInputs {
isActive?: boolean | null; // Boolean
name?: string | null; // String
};
FilterLabelsInput: {
// input type
name: string; // String!
};
FilterPollDataInput: {
// input type
afterDate?: string | null; // String
Expand All @@ -292,6 +296,10 @@ export interface NexusGenInputs {
keyword?: string | null; // String
labels?: string[] | null; // [String!]
};
FilterZonesInput: {
// input type
name: string; // String!
};
FreeResourceInput: {
// input type
poolId: string; // String!
Expand Down Expand Up @@ -2936,6 +2944,7 @@ export interface NexusGenArgTypes {
// args
after?: string | null; // String
before?: string | null; // String
filter?: NexusGenInputs['FilterLabelsInput'] | null; // FilterLabelsInput
first?: number | null; // Int
last?: number | null; // Int
};
Expand Down Expand Up @@ -3021,6 +3030,7 @@ export interface NexusGenArgTypes {
// args
after?: string | null; // String
before?: string | null; // String
filter?: NexusGenInputs['FilterZonesInput'] | null; // FilterZonesInput
first?: number | null; // Int
last?: number | null; // Int
};
Expand Down
13 changes: 11 additions & 2 deletions src/schema/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,23 @@ export const ZonesConnection = objectType({
t.nonNull.int('totalCount');
},
});

export const FilterZonesInput = inputObjectType({
name: 'FilterZonesInput',
definition: (t) => {
t.nonNull.string('name');
},
});

export const ZonesQuery = extendType({
type: 'Query',
definition: (t) => {
t.nonNull.field('zones', {
type: ZonesConnection,
args: PaginationConnectionArgs,
args: { ...PaginationConnectionArgs, filter: FilterZonesInput },
resolve: async (_, args, { prisma, tenantId }) => {
const baseArgs = { where: { tenantId } };
const { filter } = args;
const baseArgs = { where: { tenantId, ...(filter?.name ? filter : {}) } };
const result = await findManyCursorConnection(
(paginationArgs) => prisma.uniconfigZone.findMany({ ...baseArgs, ...paginationArgs }),
() => prisma.uniconfigZone.count(baseArgs),
Expand Down

0 comments on commit 4afea05

Please sign in to comment.