Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref/cli queries update #337

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4851,6 +4851,106 @@ query authCli_getConfig($envName: String!, $name: String!) {
}
}

query authCli_listServices($envName: String!, $pagination: CursorPaginationIn) {
core_listServiceBindings(envName: $envName, pagination: $pagination) {
edges {
cursor
node {
accountName
apiVersion
clusterName
creationTime
environmentName
id
interceptStatus {
intercepted
portMappings {
containerPort
servicePort
}
toAddr
}
kind
markedForDeletion
metadata {
annotations
creationTimestamp
deletionTimestamp
generation
labels
name
namespace
}
recordVersion
spec {
globalIP
hostname
ports {
appProtocol
name
nodePort
port
protocol
targetPort {
IntVal
StrVal
Type
}
}
serviceIP
serviceRef {
name
namespace
}
}
status {
checkList {
debug
description
hide
name
title
}
checks
isReady
lastReadyGeneration
lastReconcileTime
message {
RawMessage
}
resources {
apiVersion
kind
name
namespace
}
}
updateTime
}
}
pageInfo {
endCursor
hasNextPage
hasPrevPage
startCursor
}
totalCount
}
}

mutation authCli_createServiceIntercept($envName: String!, $serviceName: String!, $interceptTo: String!, $portMappings: [Github__com___kloudlite___operator___apis___crds___v1__SvcInterceptPortMappingsIn!]) {
core_createServiceIntercept(
envName: $envName
serviceName: $serviceName
interceptTo: $interceptTo
portMappings: $portMappings
)
}

mutation authCli_deleteServiceIntercept($envName: String!, $serviceName: String!) {
core_deleteServiceIntercept(envName: $envName, serviceName: $serviceName)
}

query authCli_listApps($pq: CursorPaginationIn, $envName: String!) {
apps: core_listExternalApps(pq: $pq, envName: $envName) {
edges {
Expand Down
138 changes: 138 additions & 0 deletions src/apps/auth/server/gql/cli-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,144 @@ export const cliQueries = (executor: IExecutor) => ({
}
),

cli_listServices: executor(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider extracting common GraphQL fields into reusable fragments to improve code organization

The GraphQL queries could be simplified by extracting common Kubernetes patterns into reusable fragments. This would reduce duplication while maintaining all functionality. For example:

fragment K8sMetadata on Metadata {
  annotations
  creationTimestamp
  deletionTimestamp
  generation
  labels
  name
  namespace
}

fragment PortMapping on PortMapping {
  containerPort
  servicePort
}

fragment ServiceStatus on Status {
  isReady
  lastReadyGeneration
  lastReconcileTime
  message {
    RawMessage
  }
}

query Core_listServiceBindings(
  $envName: String!
  $pagination: CursorPaginationIn
) {
  core_listServiceBindings(envName: $envName, pagination: $pagination) {
    edges {
      cursor
      node {
        metadata { ...K8sMetadata }
        interceptStatus {
          intercepted
          portMappings { ...PortMapping }
          toAddr
        }
        status { ...ServiceStatus }
        # ... other fields
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

This approach:

  • Reduces duplicate field definitions
  • Makes schema changes easier to maintain
  • Keeps queries more readable
  • Allows reuse across multiple queries

gql`
query Core_listServiceBindings(
$envName: String!
$pagination: CursorPaginationIn
) {
core_listServiceBindings(envName: $envName, pagination: $pagination) {
edges {
cursor
node {
accountName
apiVersion
clusterName
creationTime
environmentName
id
interceptStatus {
intercepted
portMappings {
containerPort
servicePort
}
toAddr
}
kind
markedForDeletion
metadata {
annotations
creationTimestamp
deletionTimestamp
generation
labels
name
namespace
}
recordVersion
spec {
globalIP
hostname
ports {
appProtocol
name
nodePort
port
protocol
targetPort {
IntVal
StrVal
Type
}
}
serviceIP
serviceRef {
name
namespace
}
}
status {
checkList {
debug
description
hide
name
title
}
checks
isReady
lastReadyGeneration
lastReconcileTime
message {
RawMessage
}
resources {
apiVersion
kind
name
namespace
}
}
updateTime
}
}
pageInfo {
endCursor
hasNextPage
hasPrevPage
startCursor
}
totalCount
}
}
`,
{
transformer: (data: any) => data.core_listServiceBindings,
vars: (_: any) => {},
}
),

cli_createServiceIntercept: executor(
gql`
mutation Core_createServiceIntercept(
$envName: String!
$serviceName: String!
$interceptTo: String!
$portMappings: [Github__com___kloudlite___operator___apis___crds___v1__SvcInterceptPortMappingsIn!]
) {
core_createServiceIntercept(
envName: $envName
serviceName: $serviceName
interceptTo: $interceptTo
portMappings: $portMappings
)
}
`,
{
transformer: (data: any) => data.core_createServiceIntercept,
vars: (_: any) => {},
}
),

cli_deleteServiceIntercept: executor(
gql`
mutation Core_deleteServiceIntercept(
$envName: String!
$serviceName: String!
) {
core_deleteServiceIntercept(
envName: $envName
serviceName: $serviceName
)
}
`,
{
transformer: (data: any) => data.core_deleteServiceIntercept,
vars: (_: any) => {},
}
),

cli_listApps: executor(
gql`
query Core_listApps($pq: CursorPaginationIn, $envName: String!) {
Expand Down
103 changes: 103 additions & 0 deletions src/generated/gql/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6626,6 +6626,109 @@ export type AuthCli_GetConfigQuery = {
};
};

export type AuthCli_ListServicesQueryVariables = Exact<{
envName: Scalars['String']['input'];
pagination?: InputMaybe<CursorPaginationIn>;
}>;

export type AuthCli_ListServicesQuery = {
core_listServiceBindings?: {
totalCount: number;
edges: Array<{
cursor: string;
node: {
accountName: string;
apiVersion?: string;
clusterName: string;
creationTime: any;
environmentName: string;
id: string;
kind?: string;
markedForDeletion?: boolean;
recordVersion: number;
updateTime: any;
interceptStatus?: {
intercepted?: boolean;
toAddr: string;
portMappings?: Array<{ containerPort: number; servicePort: number }>;
};
metadata?: {
annotations?: any;
creationTimestamp: any;
deletionTimestamp?: any;
generation: number;
labels?: any;
name: string;
namespace?: string;
};
spec?: {
globalIP: string;
hostname?: string;
serviceIP?: string;
ports?: Array<{
appProtocol?: string;
name?: string;
nodePort?: number;
port: number;
protocol?: K8s__Io___Api___Core___V1__Protocol;
targetPort?: { IntVal: number; StrVal: string; Type: number };
}>;
serviceRef?: { name: string; namespace: string };
};
status?: {
checks?: any;
isReady: boolean;
lastReadyGeneration?: number;
lastReconcileTime?: any;
checkList?: Array<{
debug?: boolean;
description?: string;
hide?: boolean;
name: string;
title: string;
}>;
message?: { RawMessage?: any };
resources?: Array<{
apiVersion: string;
kind: string;
name: string;
namespace: string;
}>;
};
};
}>;
pageInfo: {
endCursor?: string;
hasNextPage?: boolean;
hasPrevPage?: boolean;
startCursor?: string;
};
};
};

export type AuthCli_CreateServiceInterceptMutationVariables = Exact<{
envName: Scalars['String']['input'];
serviceName: Scalars['String']['input'];
interceptTo: Scalars['String']['input'];
portMappings?: InputMaybe<
| Array<Github__Com___Kloudlite___Operator___Apis___Crds___V1__SvcInterceptPortMappingsIn>
| Github__Com___Kloudlite___Operator___Apis___Crds___V1__SvcInterceptPortMappingsIn
>;
}>;

export type AuthCli_CreateServiceInterceptMutation = {
core_createServiceIntercept: boolean;
};

export type AuthCli_DeleteServiceInterceptMutationVariables = Exact<{
envName: Scalars['String']['input'];
serviceName: Scalars['String']['input'];
}>;

export type AuthCli_DeleteServiceInterceptMutation = {
core_deleteServiceIntercept: boolean;
};

export type AuthCli_ListAppsQueryVariables = Exact<{
pq?: InputMaybe<CursorPaginationIn>;
envName: Scalars['String']['input'];
Expand Down
Loading