'AWS AppSync - Defining GraphQL schema with custom directives

While defining this custom directive:

directive @hashField on INPUT_FIELD_DEFINITION

I get this error on the AWS AppSync (Schema tab):

Error parsing schema. Directive definitions are not supported.

I understand AWS provides functions that can provide similar functionalities, but these functions won't work for my use case.

What's the alternative for custom directives in AWS AppSync? Is it going to be supported in a future release?



Solution 1:[1]

Apparently it's not in their roadmap to add Directives support.

An alternative could be custom scalar types; however, it doesn't meet my requirements since I need to specify order of multiple directives applied to a particular field.

Solution 2:[2]

Interestingly, using the AWS CDK, a Directive.custom method is available at both the field and object level e.g.

import { Field, GraphqlType, InterfaceType, ObjectType, Directive } from '@aws-cdk/aws-appsync-alpha';

new ObjectType('MyObjectType', {
    definition: {
        id: GraphqlType.id({ isRequired: true }),
        name: new Field({ returnType: GraphqlType.string(), directives: [Directive.custom('@myCustomFieldDirective(param: "value")')] })
    },
    directives: [
        Directive.custom('@myCustomObjectDirective(param: "value")')
    ]
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cacho Santa
Solution 2 Aydus-Matthew