console: add formatting to action sdl

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7835
GitOrigin-RevId: e4ce96664c218a6a08124102733f7c79707fbb69
This commit is contained in:
Daniele Cammareri 2023-02-07 07:44:50 +01:00 committed by hasura-bot
parent 7027af5a05
commit aee0f7a766

View File

@ -6,6 +6,8 @@ import {
parseCustomTypes,
hydrateTypeRelationships,
} from './hasuraCustomTypeUtils';
import { format } from 'prettier/standalone';
import parserGraphql from 'prettier/parser-graphql';
export const isValidOperationName = operationName => {
return operationName === 'query' || operationName === 'mutation';
@ -22,6 +24,13 @@ const getActionTypeFromOperationType = operationType => {
return 'mutation';
};
export const formatSdl = sdl => {
return format(sdl, {
parser: 'graphql',
plugins: [parserGraphql],
});
};
const getOperationTypeFromActionType = operationType => {
if (operationType === 'query') {
return 'Query';
@ -300,17 +309,19 @@ export const getActionDefinitionSdl = (
outputType,
description
) => {
return getObjectTypeSdl({
name: getOperationTypeFromActionType(actionType),
fields: [
{
name,
arguments: args,
type: outputType,
description,
},
],
});
return formatSdl(
getObjectTypeSdl({
name: getOperationTypeFromActionType(actionType),
fields: [
{
name,
arguments: args,
type: outputType,
description,
},
],
})
);
};
export const getServerTypesFromSdl = (sdl, existingTypes) => {