Skip to content

How to restrict the use of arguments with directives? #4326

Answered by n1ru4l
Lolobstant asked this question in Q&A
Discussion options

You must be logged in to vote

You will need to have to wrap the field resolvers and add validation for the fields like the following.

import { mapSchema, MapperKind } from '@graphql-tools/utils';
import { schema } from './schema.js';

mapSchema(schema, {
  [MapperKind.OBJECT_FIELD]: fieldConfig => {
    // try to get Field from fieldName
    if (fieldConfig.args != null) {
      // TODO recursively check arguments and wrap resolver function
      for (const [_name, field] of Object.entries(fieldConfig.args)) {
        const _node = field.astNode?.directives?.find(directive => directive.name.value === 'authorize');
        // TODO: gather information on what you want to do in that case
      }

      return {
        ...

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by n1ru4l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants