@@ -517,20 +517,12 @@ export function getMutationExtendedDesc (text) {
517517 * @param {IntrospectionInputType[] } types - Types as returned by introspection query.
518518 */
519519export function processArguments ( mutation , types ) {
520- let pointer = null
521- let multiple = null
522- let required = null
523- let cylcObject = null
524- let cylcType = null
525520 for ( const arg of mutation . args ) {
526- pointer = arg . type
527- multiple = false
528- required = false
529- cylcObject = null
530- cylcType = null
531- if ( pointer ?. kind === 'NON_NULL' ) {
532- required = true
533- }
521+ let pointer = arg . type
522+ let multiple = false
523+ let cylcObject = null
524+ let cylcType = null
525+ const required = arg . type ?. kind === 'NON_NULL'
534526 while ( pointer ) {
535527 // walk down the nested type tree
536528 if ( pointer . kind === 'LIST' ) {
@@ -770,10 +762,11 @@ export function argumentSignature (arg) {
770762/** Construct a mutation string from a mutation introspection.
771763 *
772764 * @param {Mutation } mutation - A mutation as returned by an introspection query.
765+ * @param {Record<string,any> } variables
773766 *
774767 * @returns {string } A mutation string for a client to send to the server.
775768 */
776- export function constructMutation ( mutation ) {
769+ export function constructMutation ( mutation , variables ) {
777770 // the scan mutation has no arguments
778771 if ( ! mutation . args . length ) {
779772 return dedent `
@@ -788,6 +781,12 @@ export function constructMutation (mutation) {
788781 const argNames = [ ]
789782 const argTypes = [ ]
790783 for ( const arg of mutation . args ) {
784+ if ( ! arg . _required && variables ?. [ arg . name ] === arg . _default ) {
785+ // Skip optional arguments that are set to their default value -
786+ // this helps avoid back-compat issues when we add new args to the schema
787+ // TODO: remove this workaround when addressing https://github.com/cylc/cylc-ui/issues/1225
788+ continue
789+ }
791790 argNames . push ( `${ arg . name } : $${ arg . name } ` )
792791 argTypes . push ( `$${ arg . name } : ${ argumentSignature ( arg ) } ` )
793792 }
@@ -858,30 +857,32 @@ export function getMutationArgsFromTokens (mutation, tokens) {
858857 const argspec = { }
859858 let value
860859 for ( const arg of mutation . args ) {
861- const alternate = alternateFields [ arg . _cylcType ]
862- for ( let token in tokens ) {
863- if ( arg . _cylcObject && [ token , alternate ] . includes ( arg . _cylcObject ) ) {
864- if ( arg . name === 'cutoff' ) {
865- // Work around for a field we don't want filled in, see:
866- // * https://github.com/cylc/cylc-ui/issues/1222
867- // * https://github.com/cylc/cylc-ui/issues/1225
868- // TODO: Once #1225 is done the field type can be safely changed in
869- // the schema without creating a compatibility issue with the UIS.
870- continue
871- }
872- if ( arg . _cylcObject === alternate ) {
873- token = alternate
874- }
875- if ( arg . _cylcType in compoundFields ) {
876- value = compoundFields [ arg . _cylcType ] ( tokens )
877- } else {
878- value = tokens [ token ]
879- }
880- if ( arg . _multiple ) {
881- value = [ value ]
860+ if ( arg . _cylcObject ) {
861+ const alternate = alternateFields [ arg . _cylcType ]
862+ for ( let token in tokens ) {
863+ if ( [ token , alternate ] . includes ( arg . _cylcObject ) ) {
864+ if ( arg . name === 'cutoff' ) {
865+ // Work around for a field we don't want filled in, see:
866+ // * https://github.com/cylc/cylc-ui/issues/1222
867+ // * https://github.com/cylc/cylc-ui/issues/1225
868+ // TODO: Once #1225 is done the field type can be safely changed in
869+ // the schema without creating a compatibility issue with the UIS.
870+ continue
871+ }
872+ if ( arg . _cylcObject === alternate ) {
873+ token = alternate
874+ }
875+ if ( arg . _cylcType in compoundFields ) {
876+ value = compoundFields [ arg . _cylcType ] ( tokens )
877+ } else {
878+ value = tokens [ token ]
879+ }
880+ if ( arg . _multiple ) {
881+ value = [ value ]
882+ }
883+ argspec [ arg . name ] = value
884+ break
882885 }
883- argspec [ arg . name ] = value
884- break
885886 }
886887 }
887888 if ( ! argspec [ arg . name ] ) {
@@ -940,14 +941,14 @@ async function _mutateError (mutationName, err, response) {
940941 * Call a mutation.
941942 *
942943 * @param {Mutation } mutation
943- * @param {Object } variables
944+ * @param {Record<string,any> } variables
944945 * @param {ApolloClient } apolloClient
945946 * @param {string= } cylcID
946947 *
947948 * @returns {(MutationResponse | Promise<MutationResponse>) } {status, msg}
948949 */
949950export async function mutate ( mutation , variables , apolloClient , cylcID ) {
950- const mutationStr = constructMutation ( mutation )
951+ const mutationStr = constructMutation ( mutation , variables )
951952 // eslint-disable-next-line no-console
952953 console . debug ( mutationStr , variables )
953954
0 commit comments