refactor: introduce input in gql mutations

This commit is contained in:
Ali BARIN
2022-03-08 12:20:34 +01:00
committed by Ömer Faruk Aydın
parent f5f7a998ca
commit 030d886cf7
21 changed files with 67 additions and 39 deletions

View File

@@ -217,11 +217,25 @@ input DeleteFlowInput {
} }
input CreateStepInput { input CreateStepInput {
input: StepInput! id: String
previousStepId: String
key: String
appKey: String
connection: StepConnectionInput
flow: StepFlowInput
parameters: JSONObject
previousStep: PreviousStepInput
} }
input UpdateStepInput { input UpdateStepInput {
input: StepInput! id: String
previousStepId: String
key: String
appKey: String
connection: StepConnectionInput
flow: StepFlowInput
parameters: JSONObject
previousStep: PreviousStepInput
} }
input DeleteStepInput { input DeleteStepInput {

View File

@@ -55,7 +55,7 @@ function AppConnectionRow(props: AppConnectionRowProps): React.ReactElement {
const onContextMenuAction = React.useCallback(async (event, action: { [key: string]: string }) => { const onContextMenuAction = React.useCallback(async (event, action: { [key: string]: string }) => {
if (action.type === 'delete') { if (action.type === 'delete') {
await deleteConnection({ await deleteConnection({
variables: { id }, variables: { input: { id } },
update: (cache) => { update: (cache) => {
const connectionCacheId = cache.identify({ const connectionCacheId = cache.identify({
__typename: 'Connection', __typename: 'Connection',
@@ -71,7 +71,7 @@ function AppConnectionRow(props: AppConnectionRowProps): React.ReactElement {
enqueueSnackbar(formatMessage('connection.deletedMessage'), { variant: 'success' }); enqueueSnackbar(formatMessage('connection.deletedMessage'), { variant: 'success' });
} else if (action.type === 'test') { } else if (action.type === 'test') {
setVerificationVisible(true); setVerificationVisible(true);
testConnection({ variables: { id } }); testConnection({ variables: { input: { id } } });
} }
}, [deleteConnection, id, testConnection, formatMessage, enqueueSnackbar]); }, [deleteConnection, id, testConnection, formatMessage, enqueueSnackbar]);

View File

@@ -50,12 +50,21 @@ function ChooseAccountSubstep(props: ChooseAccountSubstepProps): React.ReactElem
loading: testResultLoading, loading: testResultLoading,
refetch: retestConnection refetch: retestConnection
} }
] = useLazyQuery (TEST_CONNECTION, { variables: { id: connection?.id, }}); ] = useLazyQuery(
TEST_CONNECTION,
{
variables: {
input: { id: connection?.id, }
}
}
);
React.useEffect(() => { React.useEffect(() => {
if (connection?.id) { if (connection?.id) {
testConnection({ testConnection({
variables: { id: connection?.id }, variables: {
input: { id: connection.id, }
}
}); });
} }
// intentionally no dependencies for initial test // intentionally no dependencies for initial test
@@ -88,7 +97,9 @@ function ChooseAccountSubstep(props: ChooseAccountSubstepProps): React.ReactElem
React.useEffect(() => { React.useEffect(() => {
if (step.connection?.id) { if (step.connection?.id) {
retestConnection({ retestConnection({
input: {
id: step.connection.id, id: step.connection.id,
},
}); });
} }
}, [step.connection?.id, retestConnection]) }, [step.connection?.id, retestConnection])

View File

@@ -27,9 +27,11 @@ export default function EditorLayout(): React.ReactElement {
const onFlowNameUpdate = React.useCallback(async (name: string) => { const onFlowNameUpdate = React.useCallback(async (name: string) => {
await updateFlow({ await updateFlow({
variables: { variables: {
input: {
id: flowId, id: flowId,
name, name,
}, },
},
optimisticResponse: { optimisticResponse: {
__typename: 'Mutation', __typename: 'Mutation',
updateFlow: { updateFlow: {

View File

@@ -51,8 +51,6 @@ export default function FlowStep(props: FlowStepProps): React.ReactElement | nul
{ {
data: stepWithTestExecutionsData, data: stepWithTestExecutionsData,
called: stepWithTestExecutionsCalled, called: stepWithTestExecutionsCalled,
loading: stepWithTestExecutionsLoading,
error: stepWithTestExecutionsError
}, },
] = useLazyQuery(GET_STEP_WITH_TEST_EXECUTIONS, { ] = useLazyQuery(GET_STEP_WITH_TEST_EXECUTIONS, {
fetchPolicy: 'network-only', fetchPolicy: 'network-only',
@@ -62,8 +60,10 @@ export default function FlowStep(props: FlowStepProps): React.ReactElement | nul
if (!stepWithTestExecutionsCalled && !collapsed && !isTrigger) { if (!stepWithTestExecutionsCalled && !collapsed && !isTrigger) {
getStepWithTestExecutions({ getStepWithTestExecutions({
variables: { variables: {
input: {
stepId: step.id, stepId: step.id,
}, },
},
}); });
} }
}, [collapsed, stepWithTestExecutionsCalled, getStepWithTestExecutions, step.id, isTrigger]); }, [collapsed, stepWithTestExecutionsCalled, getStepWithTestExecutions, step.id, isTrigger]);

View File

@@ -21,7 +21,7 @@ function FlowStepContextMenu(props: FlowStepContextMenuProps): React.ReactElemen
const deleteActionHandler = React.useCallback(async (event: React.SyntheticEvent) => { const deleteActionHandler = React.useCallback(async (event: React.SyntheticEvent) => {
event.stopPropagation(); event.stopPropagation();
await deleteStep({ variables: { id: stepId }}); await deleteStep({ variables: { input: { id: stepId } } });
}, [stepId]); }, [stepId]);
return ( return (

View File

@@ -39,8 +39,10 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
const handleSubmit = React.useCallback(() => { const handleSubmit = React.useCallback(() => {
executeFlow({ executeFlow({
variables: { variables: {
input: {
stepId: step.id, stepId: step.id,
} },
},
}) })
}, [onSubmit, step.id]); }, [onSubmit, step.id]);
const onToggle = expanded ? onCollapse : onExpand; const onToggle = expanded ? onCollapse : onExpand;

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const CREATE_AUTH_DATA = gql` export const CREATE_AUTH_DATA = gql`
mutation createAuthData($id: String!) { mutation CreateAuthData($input: CreateAuthDataInput) {
createAuthData(id: $id) { createAuthData(input: $input) {
url url
} }
} }

View File

@@ -2,10 +2,9 @@ import { gql } from '@apollo/client';
export const CREATE_CONNECTION = gql` export const CREATE_CONNECTION = gql`
mutation CreateConnection( mutation CreateConnection(
$key: AvailableAppsEnumType! $input: CreateConnectionInput
$formattedData: JSONObject!
) { ) {
createConnection(key: $key, formattedData: $formattedData) { createConnection(input: $input) {
id id
key key
verified verified

View File

@@ -1,7 +1,7 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const CREATE_FLOW = gql` export const CREATE_FLOW = gql`
mutation createFlow($input: FlowInput) { mutation CreateFlow($input: CreateFlowInput) {
createFlow(input: $input) { createFlow(input: $input) {
id id
name name

View File

@@ -1,7 +1,7 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const CREATE_STEP = gql` export const CREATE_STEP = gql`
mutation CreateStep($input: StepInput!) { mutation CreateStep($input: CreateStepInput) {
createStep(input: $input) { createStep(input: $input) {
id id
type type

View File

@@ -1,7 +1,7 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const DELETE_CONNECTION = gql` export const DELETE_CONNECTION = gql`
mutation DeleteConnection($id: String!) { mutation DeleteConnection($input: DeleteConnectionInput) {
deleteConnection(id: $id) deleteConnection(input: $input)
} }
`; `;

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const DELETE_STEP = gql` export const DELETE_STEP = gql`
mutation DeleteStep($id: String!) { mutation DeleteStep($input: DeleteStepInput) {
deleteStep(id: $id) { deleteStep(input: $input) {
id id
flow { flow {
id id

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const EXECUTE_FLOW = gql` export const EXECUTE_FLOW = gql`
mutation ExecuteFlow($stepId: String!) { mutation ExecuteFlow($input: ExecuteFlowInput) {
executeFlow(stepId: $stepId) { executeFlow(input: $input) {
step { step {
id id
status status

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const RESET_CONNECTION = gql` export const RESET_CONNECTION = gql`
mutation ResetConnection($id: String!) { mutation ResetConnection($input: ResetConnectionInput) {
resetConnection(id: $id) { resetConnection(input: $input) {
id id
} }
} }

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const UPDATE_CONNECTION = gql` export const UPDATE_CONNECTION = gql`
mutation UpdateConnection($id: String!, $formattedData: JSONObject!) { mutation UpdateConnection($input: UpdateConnectionInput) {
updateConnection(id: $id, formattedData: $formattedData) { updateConnection(input: $input) {
id id
key key
verified verified

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const UPDATE_FLOW = gql` export const UPDATE_FLOW = gql`
mutation UpdateFlow($id: String!, $name: String!) { mutation UpdateFlow($input: UpdateFlowInput) {
updateFlow(id: $id, name: $name) { updateFlow(input: $input) {
id id
name name
} }

View File

@@ -1,7 +1,7 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const UPDATE_STEP = gql` export const UPDATE_STEP = gql`
mutation UpdateStep($input: StepInput!) { mutation UpdateStep($input: UpdateStepInput) {
updateStep(input: $input) { updateStep(input: $input) {
id id
type type

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const VERIFY_CONNECTION = gql` export const VERIFY_CONNECTION = gql`
mutation VerifyConnection($id: String!) { mutation VerifyConnection($input: VerifyConnectionInput) {
verifyConnection(id: $id) { verifyConnection(input: $input) {
id id
verified verified
formattedData { formattedData {

View File

@@ -10,7 +10,7 @@ enum AuthenticationSteps {
const processMutation = async (step: IAuthenticationStep, variables: IJSONObject) => { const processMutation = async (step: IAuthenticationStep, variables: IJSONObject) => {
const mutation = MUTATIONS[step.name]; const mutation = MUTATIONS[step.name];
const mutationResponse = await apolloClient.mutate({ mutation, variables }); const mutationResponse = await apolloClient.mutate({ mutation, variables: { input: variables } });
const responseData = mutationResponse.data[step.name]; const responseData = mutationResponse.data[step.name];
return responseData; return responseData;