0

I have the following directive in y GraphQL schema to check if arguments are real slugs

directive @slug on ARGUMENT_DEFINITION

Query {
   subject(id: ID! @slug): Subject
}

We had a working solution before using SchemaDirectiveVisitor from apollo-server-express, which to my understanding was just an re export from graphql-tools. As this was removed with the latest major release we have to refactor it. As far as I understand this, also the graphql-tools API has changed, so to react on directives we have to follow the examples here.

So this is what I have so far but it doesn't go into the fieldConfig.resolve function at all:

export default function (schema) {
    return mapSchema(schema, {
        [MapperKind.ARGUMENT]: fieldConfig => {
            const slugDirective = getDirective(schema, fieldConfig, 'slug')?.[0]
            if (slugDirective) {
                const { resolve = defaultFieldResolver } = fieldConfig
                fieldConfig.resolve = async function (
                    source,
                    args,
                    context,
                    info
                ) {
                    const result = await resolve(source, args, context, info)
                    console.log('result', result)
                }
                return fieldConfig
            }
        },
    })
}
Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
  • MapperKind.ARGUMENT maps to an argumentConfig not a fieldConfig, so there is no resolver. I'm in the process of figuring this out myself but if you've managed to find a solution to this, I'd take it ;) – Jonathan Adami Mar 15 '22 at 20:40
  • it returns a type, there is a way to use a GraphQLScalarType to hijack serialize, parseValue and parseLiteral and that should do the trick – Jonathan Adami Mar 15 '22 at 20:46

0 Answers0