Skip to content

Commit

Permalink
Add graphql api creation by SDL url and introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
nisan-abeywickrama committed Jan 4, 2025
1 parent 759164f commit f82bdfa
Show file tree
Hide file tree
Showing 6 changed files with 385 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default function DefaultAPIForm(props) {
const {
onChange, onValidate, api, isAPIProduct, multiGateway,
isWebSocket, children, appendChildrenBeforeEndpoint, hideEndpoint,
readOnlyAPIEndpoint,
} = props;

const [validity, setValidity] = useState({});
Expand Down Expand Up @@ -594,6 +595,7 @@ export default function DefaultAPIForm(props) {
<TextField
fullWidth
id='itest-id-apiendpoint-input'
disabled={readOnlyAPIEndpoint !== null}
label={(
<FormattedMessage
id='Apis.Create.Components.DefaultAPIForm.api.endpoint'
Expand Down Expand Up @@ -756,6 +758,7 @@ DefaultAPIForm.defaultProps = {
onValidate: () => { },
api: {}, // Uncontrolled component
isWebSocket: false,
readOnlyAPIEndpoint: null,
};
DefaultAPIForm.propTypes = {
api: PropTypes.shape({}),
Expand All @@ -764,4 +767,5 @@ DefaultAPIForm.propTypes = {
isWebSocket: PropTypes.shape({}),
onChange: PropTypes.func.isRequired,
onValidate: PropTypes.func,
readOnlyAPIEndpoint: PropTypes.string,
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ export default function ApiCreateGraphQL(props) {
case 'version':
case 'gatewayType':
case 'endpoint':
return { ...currentState, [action]: value };
case 'context':
case 'isFormValid':
return { ...currentState, [action]: value };
case 'inputType':
return { ...currentState, [action]: value, inputValue: value === 'url' ? '' : null };
return { ...currentState, [action]: value, inputValue: value === ('url' || 'endpoint') ? '' : null };
case 'graphQLInfo':
return { ...currentState, [action]: value };
case 'preSetAPI':
Expand Down Expand Up @@ -145,6 +146,7 @@ export default function ApiCreateGraphQL(props) {
endpoint,
gatewayType,
implementationType,
inputType,
inputValue,
graphQLInfo: { operations },
} = apiInputs;
Expand All @@ -166,7 +168,6 @@ export default function ApiCreateGraphQL(props) {
policies,
operations,
};
const uploadMethod = 'file';
if (endpoint) {
additionalProperties.endpointConfig = {
endpoint_type: 'http',
Expand All @@ -182,10 +183,14 @@ export default function ApiCreateGraphQL(props) {
const apiData = {
additionalProperties: JSON.stringify(additionalProperties),
implementationType,
[uploadMethod]: uploadMethod,
file: inputValue,
};

if (inputType === 'file') {
apiData.file = inputValue;
} else if (inputType === 'url' || inputType === 'endpoint') {
apiData.schema = apiInputs.graphQLInfo.graphQLSchema.schemaDefinition;
}

newApi
.importGraphQL(apiData)
.then((response) => {
Expand Down Expand Up @@ -222,13 +227,14 @@ export default function ApiCreateGraphQL(props) {
<Typography variant='h5'>
<FormattedMessage
id='Apis.Create.GraphQL.ApiCreateGraphQL.heading'
defaultMessage='Create an API using a GraphQL SDL definition'
defaultMessage='Create a GraphQL API'
/>
</Typography>
<Typography variant='caption'>
<FormattedMessage
id='Apis.Create.GraphQL.ApiCreateGraphQL.sub.heading'
defaultMessage='Create an API by importing an existing GraphQL SDL definition.'
defaultMessage={'Create a GraphQL API by importing a SDL definition'
+ ' from a file or URL, or by using introspection.'}
/>
</Typography>
</>
Expand Down Expand Up @@ -272,6 +278,7 @@ export default function ApiCreateGraphQL(props) {
multiGateway={multiGateway}
api={apiInputs}
isAPIProduct={false}
readOnlyAPIEndpoint={apiInputs.inputType==='endpoint' ? apiInputs.endpoint : null}
/>
)}
</Grid>
Expand Down
Loading

0 comments on commit f82bdfa

Please sign in to comment.