Error: Do not know how to handle this type of mutation. Mutation does not follow naming convention

315 views Asked by At

Using the GRANDstack Starter template project, I'm using apollo-server in combination with neo4j. I have a CreateParticipant mutation (defined in the schema.graphql with a @cypher directive) that I want to reuse for a new mutation.

The simplified resolver that gets passed into the augmented schema looks like this:

const resolvers = {
  Mutation: {
    UploadCSV: async (parent, { file }, context, info) => {
      // some data processing using file omitted
      const payload = { name: 'Just a name' }
      const result = resolvers.Mutation.CreateParticipant(
        parent,
        payload,
        context,
        info
      )
      return 'thanks StackOverflow'
    },
  },
}

The mutations are defined in the schema.graphql file like this:

CreateParticipant(name: String!, id: ID = null): Participant
@cypher(
  statement: """
  CREATE (par:Participant {
    name: $name,
    id: coalesce($id, apoc.create.uuid())
  })
  RETURN par
  """
)

UploadCSV(file: Upload!): String

When I try to upload a file now via the frontend, apollo-server throws an error when executing resolvers.Mutation.CreateParticipant(parent, payload, context, info). Payload is an object with key/value pairs that the mutation expects.

The thrown error is:

Error: Do not know how to handle this type of mutation. Mutation does not follow naming convention.

I'm wondering if passing the unmodified info is the reason this isn't working.

1

There are 1 answers

4
Edward Romero On

Don’t try to call the mutation inside another. Instead pull the create participant logic out and import the functions that are generic. This allows you to keep a separation of concerns between the upload csv and the create participants mutations.

Some good resources:

Nested Graphql Resolvers

Reusing Resolvers Conversation