Skip to content

add an argument for one operation seems too complex #137

Closed
@ziedHamdi

Description

@ziedHamdi

Hi,

I have an entity called complaint that has many attachments in it. When editing a complaint, the user may want to remove some attachments, so I want to an argument that contains the list of removed attachments to the query.

To do that, I suuposed I cannot add an argument with wrapResolve, so I decided to nest the existing updateOne resolver and take the infos from it as follows:

const complaintUpdateOneResolver = ComplaintTC.getResolver('updateOne');
console.log("complaintUpdateOne: ", complaintUpdateOneResolver)
schemaComposer.rootMutation().addFields({
	complaintUpdateOne: new Resolver({
		name: complaintUpdateOneResolver.name,
		kind: complaintUpdateOneResolver.kind,
		type: complaintUpdateOneResolver.type,
		args: [...complaintUpdateOneResolver.args, {'attachmentsToRemove': ['String']}],
		resolve: async (params) => {
			console.log("args of complaintUpdateOne: ", complaintUpdateOneResolver.args)
			complaintUpdateOneResolver.resolve(params)
			const {args, context} = params;
			// do some other job here: remove attachment files from storage
		}
	},
    //...
})

I have an issue with this approach :

  • I don't know how to modify the record field: UpdateOneComplaintInput ???
complaintUpdateOne:  Resolver {
  name: 'updateOne',
  displayName: 'Complaint.updateOne',
  parent: null,
  kind: 'mutation',
  description:
   'Update one document: 1) Retrieve one document via findOne. 2) Apply updates to mongoose document. 3) Mongoose applies defaults, setters, hooks and validation. 4) And save it.',
  type: TypeComposer { gqType: UpdateOneComplaintPayload },
  args:
   { record: { type: UpdateOneComplaintInput! },
     filter:
      { type: FilterUpdateOneComplaintInput,
        description: 'Filter by fields' },
     sort: { type: [EnumTypeComposer] },
     skip: { type: 'Int' } },
  resolve: [Function: resolve] }

Do i have to create an new resolver from scratch for that? (I added a qestion on SO : https://stackoverflow.com/questions/53223092/how-to-intercept-graphql-compose-mongoose-schema-creation-to-add-an-argument-in)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions