Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,24 @@ export default function ProvideGraphQL(props) {
);

function validateURL(value) {
const state = APIValidation.url.required().validate(value).error;
if (state === null) {
setIsValidating(true);
debouncedValidateURLOrEndpoint(apiInputs.inputValue);
// For GraphQL Endpoint, skip strict URL validation and allow domain names without protocol
if (inputType === ProvideGraphQL.INPUT_TYPES.ENDPOINT) {
if (value && value.trim() !== '') {
setIsValidating(true);
debouncedValidateURLOrEndpoint(apiInputs.inputValue);
} else {
setValidity({ ...isValid, url: { message: 'GraphQL Endpoint should not be empty' } });
onValidate(false);
}
} else {
setValidity({ ...isValid, url: state });
onValidate(false);
const state = APIValidation.url.required().validate(value).error;
if (state === null) {
setIsValidating(true);
debouncedValidateURLOrEndpoint(apiInputs.inputValue);
} else {
setValidity({ ...isValid, url: state });
onValidate(false);
}
}
}
Comment on lines 196 to 216
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix parameter usage: validate the passed value, not stale state.

The conditional validation logic correctly addresses the reported issue by allowing domain names for GraphQL Endpoints. However, there's a significant concern with parameter usage:

Issue: Lines 201 and 210 pass apiInputs.inputValue to debouncedValidateURLOrEndpoint, but the function receives value as a parameter from the blur event (lines 390, 428). Since onChange updates apiInputs.inputValue asynchronously and onBlur fires immediately after, there's a potential race condition where the state hasn't been updated yet, causing validation of a stale value rather than what the user just entered.

Solution: Use the value parameter consistently throughout the function.

Apply this diff:

     function validateURL(value) {
         // For GraphQL Endpoint, skip strict URL validation and allow domain names without protocol
         if (inputType === ProvideGraphQL.INPUT_TYPES.ENDPOINT) {
             if (value && value.trim() !== '') {
                 setIsValidating(true);
-                debouncedValidateURLOrEndpoint(apiInputs.inputValue);
+                debouncedValidateURLOrEndpoint(value);
             } else {
                 setValidity({ ...isValid, url: { message: 'GraphQL Endpoint should not be empty' } });
                 onValidate(false);
             }
         } else {
             const state = APIValidation.url.required().validate(value).error;
             if (state === null) {
                 setIsValidating(true);
-                debouncedValidateURLOrEndpoint(apiInputs.inputValue);
+                debouncedValidateURLOrEndpoint(value);
             } else {
                 setValidity({ ...isValid, url: state });
                 onValidate(false);
             }
         }
     }

Minor note: Storing endpoint validation state in isValid.url (line 203) works functionally but is semantically confusing. Consider using a more generic key like isValid.input or isValid.value in a future refactor.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function validateURL(value) {
const state = APIValidation.url.required().validate(value).error;
if (state === null) {
setIsValidating(true);
debouncedValidateURLOrEndpoint(apiInputs.inputValue);
// For GraphQL Endpoint, skip strict URL validation and allow domain names without protocol
if (inputType === ProvideGraphQL.INPUT_TYPES.ENDPOINT) {
if (value && value.trim() !== '') {
setIsValidating(true);
debouncedValidateURLOrEndpoint(apiInputs.inputValue);
} else {
setValidity({ ...isValid, url: { message: 'GraphQL Endpoint should not be empty' } });
onValidate(false);
}
} else {
setValidity({ ...isValid, url: state });
onValidate(false);
const state = APIValidation.url.required().validate(value).error;
if (state === null) {
setIsValidating(true);
debouncedValidateURLOrEndpoint(apiInputs.inputValue);
} else {
setValidity({ ...isValid, url: state });
onValidate(false);
}
}
}
function validateURL(value) {
// For GraphQL Endpoint, skip strict URL validation and allow domain names without protocol
if (inputType === ProvideGraphQL.INPUT_TYPES.ENDPOINT) {
if (value && value.trim() !== '') {
setIsValidating(true);
debouncedValidateURLOrEndpoint(value);
} else {
setValidity({ ...isValid, url: { message: 'GraphQL Endpoint should not be empty' } });
onValidate(false);
}
} else {
const state = APIValidation.url.required().validate(value).error;
if (state === null) {
setIsValidating(true);
debouncedValidateURLOrEndpoint(value);
} else {
setValidity({ ...isValid, url: state });
onValidate(false);
}
}
}
🤖 Prompt for AI Agents
In
portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/GraphQL/Steps/ProvideGraphQL.jsx
around lines 196 to 216, the function validateURL uses apiInputs.inputValue when
calling debouncedValidateURLOrEndpoint, which can validate a stale value due to
async state updates; change those calls to pass the local parameter value
instead (i.e., call debouncedValidateURLOrEndpoint(value)) so the blur handler
validates the exact input passed in; keep the existing setIsValidating,
setValidity and onValidate behavior unchanged.


Expand Down
Loading