Skip to content

Commit

Permalink
bugfix: GraphQL variable type error (#2011)
Browse files Browse the repository at this point in the history
* remove unused code

* use `/admin/gql` instead of `/admin/graphql` in client sdk

* fix variables for resource policy mutations

* fix graphql variable type for credentail mutations

* fix: access `globalThis.backendaiclient.supports` after connected
  • Loading branch information
yomybaby authored Nov 5, 2023
1 parent 9b045f6 commit a293e28
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
1 change: 0 additions & 1 deletion react/src/components/UserSettingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ const UserSettingModal: React.FC<Props> = ({
confirmLoading={isInFlightCommitModifyUserSetting}
{...baiModalProps}
>
<div>{sudoSessionEnabledSupported ? 'true' : 'false'}</div>
<Form
preserve={false}
form={form}
Expand Down
2 changes: 1 addition & 1 deletion src/components/backend-ai-credential-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export default class BackendAICredentialView extends BackendAIPage {
*/

const resource_policy = this.resourcePolicy.value;
const rate_limit = this.rateLimit.value;
const rate_limit = parseInt(this.rateLimit.value);
// Read resources
globalThis.backendaiclient.keypair
.add(user_id, is_active, is_admin, resource_policy, rate_limit)
Expand Down
7 changes: 6 additions & 1 deletion src/components/backend-ai-environment-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { customElement, property } from 'lit/decorators.js';
export default class BackendAIEnvironmentView extends BackendAIPage {
@property({ type: String }) images = Object();
@property({ type: Boolean }) is_superadmin = false;
@property({ type: Boolean }) isSupportContainerRegistryGraphQL = false;
@property({ type: String }) _activeTab = 'image-lists';

static get styles(): CSSResultGroup {
Expand Down Expand Up @@ -111,12 +112,16 @@ export default class BackendAIEnvironmentView extends BackendAIPage {
'backend-ai-connected',
() => {
this.is_superadmin = globalThis.backendaiclient.is_superadmin;
this.isSupportContainerRegistryGraphQL =
globalThis.backendaiclient.supports('container-registry-gql');
},
true,
);
} else {
// already connected
this.is_superadmin = globalThis.backendaiclient.is_superadmin;
this.isSupportContainerRegistryGraphQL =
globalThis.backendaiclient.supports('container-registry-gql');
}
return false;
}
Expand Down Expand Up @@ -181,7 +186,7 @@ export default class BackendAIEnvironmentView extends BackendAIPage {
?active="${this._activeTab === 'resource-template-lists'}"
></backend-ai-resource-preset-list>
<div id="registry-lists" class="tab-content">
${globalThis.backendaiclient.supports('container-registry-gql') &&
${this.isSupportContainerRegistryGraphQL &&
this._activeTab === 'registry-lists'
? html`
<div class="flex" style="height:calc(100vh - 183px);">
Expand Down
57 changes: 39 additions & 18 deletions src/components/backend-ai-resource-policy-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,14 @@ export default class BackendAIResourcePolicyList extends BackendAIPage {
label="${_t('resourcePolicy.AllowedHosts')}"
style="width:100%;"
></backend-ai-multi-select>
<div class="horizontal layout justified" style="width:100%;">
<div
class="horizontal layout justified"
style=${globalThis.backendaiclient.supports(
'max-vfolder-count-in-user-resource-policy',
)
? 'display:none;'
: 'width:100%;'}
>
<mwc-textfield
label="${_t('credential.Max#')}"
class="discrete"
Expand Down Expand Up @@ -613,19 +620,25 @@ export default class BackendAIResourcePolicyList extends BackendAIPage {
`
: html``}
</div>
<div class="layout horizontal wrap center">
<div class="layout horizontal configuration">
<mwc-icon class="fg green indicator">folder</mwc-icon>
<span>
${this._displayResourcesByResourceUnit(
rowData.item.max_vfolder_count,
false,
'max_vfolder_count',
)}
</span>
<span class="indicator">Folders</span>
</div>
</div>
${globalThis.backendaiclient.supports(
'max-vfolder-count-in-user-resource-policy',
)
? html``
: html`
<div class="layout horizontal wrap center">
<div class="layout horizontal configuration">
<mwc-icon class="fg green indicator">folder</mwc-icon>
<span>
${this._displayResourcesByResourceUnit(
rowData.item.max_vfolder_count,
false,
'max_vfolder_count',
)}
</span>
<span class="indicator">Folders</span>
</div>
</div>
`}
`,
root,
);
Expand Down Expand Up @@ -1076,18 +1089,26 @@ export default class BackendAIResourcePolicyList extends BackendAIPage {
const input = {
default_for_unspecified: 'UNLIMITED',
total_resource_slots: JSON.stringify(total_resource_slots),
max_concurrent_sessions: this.concurrencyLimit.value,
max_containers_per_session: this.containerPerSessionLimit.value,
max_concurrent_sessions: parseInt(this.concurrencyLimit.value),
max_containers_per_session: parseInt(this.containerPerSessionLimit.value),
idle_timeout: this.idleTimeout.value,
max_vfolder_count: this.vfolderCountLimitInput.value,

allowed_vfolder_hosts: vfolder_hosts,
};

if (
!globalThis.backendaiclient.supports(
'max-vfolder-count-in-user-resource-policy',
)
) {
input.max_vfolder_count = this.vfolderCountLimitInput.value;
}

if (this.enableSessionLifetime) {
this._validateUserInput(this.sessionLifetime);
this.sessionLifetime.value =
this.sessionLifetime.value === '' ? '0' : this.sessionLifetime.value;
input['max_session_lifetime'] = this.sessionLifetime.value;
input['max_session_lifetime'] = parseInt(this.sessionLifetime.value);
}

return input;
Expand Down
7 changes: 5 additions & 2 deletions src/lib/backend.ai-client-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,9 @@ class Client {
if (this.isManagerVersionCompatibleWith('23.09.2')) {
this._features['container-registry-gql'] = true;
}
if (this.isManagerVersionCompatibleWith('24.03.0')) {
this._features['max-vfolder-count-in-user-resource-policy'] = true;
}
}

/**
Expand Down Expand Up @@ -1489,12 +1492,12 @@ class Client {
};
let rqst = this.newSignedRequest(
'POST',
`/admin/graphql`,
`/admin/gql`,
query,
null,
secure,
);
return this._wrapWithPromise(rqst, false, signal, timeout, retry);
return this._wrapWithPromise(rqst, false, signal, timeout, retry).then(r => r.data);
}

/**
Expand Down

0 comments on commit a293e28

Please sign in to comment.