maticzav / graphql-middleware

Split up your GraphQL resolvers in middleware functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

not working on mutations, but working on query.

wuichen opened this issue · comments

hi all, i am using nextjs, api routes, and nexus. trying to implement the middleware like below. its working on query, but not mutation. what could be the possible reason?


const middleware = {
  Query: {
    findManyProduct: async (resolve, parent, args, context, info) => {
      console.log('this gets called')
      const result = await resolve(parent, args, context, info)

      return result
    }
  },
  Mutation: {
    // createOneCompany: slugCounter,
    createOneProduct: async (resolve, parent, args, context, info) => {
      console.log('this doesnt')
      const result = await resolve(parent, args, context, info)

      return result
}}
import * as types from './graphql'
import { paljs } from '@paljs/nexus'
import { join } from 'path'
import { applyMiddleware } from 'graphql-middleware'
import permissions from './middleware/permissions'
import slugCounter from './middleware/slugCounter'

export const schema = applyMiddleware(
  makeSchema({
    types,
    // plugins: [paljs({ includeAdmin: true })],
    plugins: [paljs()],
    outputs: {
      schema: join(process.cwd(), 'src', 'generated', 'schema.graphql'),
      typegen: join(process.cwd(), 'src', 'generated', 'nexus-typegen.ts'),
    },
    typegenAutoConfig: {
      sources: [
        {
          source: '@prisma/client',
          alias: 'prisma',
        },
        {
          source: require.resolve('./context'),
          alias: 'Context',
        },
      ],
      contextType: 'Context.Context',
    },
  }),
  slugCounter,
  permissions,
)

realized its problem on my end. closing