graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
828 stars 118 forks source link

Add new pagination: 'required' option #902

Open P4sca1 opened 4 years ago

P4sca1 commented 4 years ago

An option to enforce pagination parameters like take (prisma strategy) or first / last (relay strategy) on a per field basis would be great. pagination: true would enable optional pagination (as it is now) and pagination: 'required' would mark the fields in the graphql schema as required and also validate that the args are set at runtime. This would be helpful in scenarios where a query cost analyzer is used, which requires those arguments to calculate the correct cost of the query.

Workaround for the prisma strategy:

resolve: async (user, args, ctx, info, originalResolve) => {
  if (!args.take)
    throw new ForbiddenError('You need to specify the take argument.')

  return originalResolve(user, args, ctx, info)
}

The workaround has the disadvantage that the graphql schema marks the take argument as optional, but it is required.

P4sca1 commented 4 years ago

A more flexible solution would be to allow the pagination option to be an object. So you could do

pagination: {
  required: true
}

See https://github.com/graphql-nexus/nexus-plugin-prisma/issues/841#issuecomment-711436792