AWS AppSync - Defining GraphQL schema with custom directives
Asked Answered
M

2

7

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?

Mook answered 3/2, 2020 at 23:38 Comment(1)
in the middle of 2023... nothing arise about this?Alicea
M
3

Looks like they don't have plans to support Directives anytime soon.

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.

Mook answered 10/2, 2020 at 21:25 Comment(3)
Just a FYI, AWS AppSync does not support custom scalars...Aguilera
How do you know that it is not on AWS roadmap ? Can you share a link ?Fogbow
I'm not sure about their roadmap actually, I was just referring that at that point in time (2020) they did not support it. Re-phrased my answer now to clarify that.Mook
H
0

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")')
    ]
});
Housewifely answered 5/5, 2022 at 0:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.