Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppSync reject directive definition saying "Directive definitions are not supported." #25

Open
xinguaws opened this issue Jun 30, 2020 · 8 comments

Comments

@xinguaws
Copy link

in my schema I have subscription defined using @aws_subscribe

type Subscription {
  onCreateAlbum(owner: String!): Album @aws_subscribe(mutations: ["createAlbum"])
}

If I don't define following when I merge two schema file:
directive @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION
it will throw error saying "Error(1): Unknown directive "aws_subscribe""

If add the directive definition, when I upload to AppSync, it got rejected saying "Directive definitions are not supported."

How would I be able to merge the schema and use it for AppSync at the same time?

@hsehweil
Copy link
Contributor

As you mentioned you are seeing this issue because AppSync does add these directives definitions on top of your schema as part of AppSync core implementations. We decided not to add support to AppSync directives into this library because this is an open source solution and should NOT be limited to AppSync.
But here is a suggestion for a workaround (i have not tested it myself):
Define all AppSync directives into your local workspace and do not check that in. Similar to this issue is how to deal with AppSync predefined scalars: #15

@xinguaws
Copy link
Author

@hsehweil how do you not check in directives defined in local workspace when you do schema merge? quoting from #15 graphql-schema-utilities -s "{aws/types.graphql,schema.graphql,schema/**/*.graphql}"

@chimon2000
Copy link

Why not just update the tool to be able to ignore directives and scalar types? I'm not sure how useful this tool would be in other environments since most alternatives (Hasura, Apollo, etc) support schema stitching or federation, and I'd imagine people are arriving here because of the failure of AWS to handle this.

Also, this workaround is saddening because not checking in that file means every member of the team needs to remember to add it to their source. It creates a convention that is hard to enforce for large teams or for multiple product teams working in the same repository.

@half2me
Copy link

half2me commented May 20, 2021

@hsehweil how do you not check in directives defined in local workspace when you do schema merge? quoting from #15 graphql-schema-utilities -s "{aws/types.graphql,schema.graphql,schema/**/*.graphql}"

I have the same question. Right now I'm unable to use this with AppSync, because it either fails validation, or if I add in the custom types, it gets merged into the final output, and AppSync just rejects it.

@half2me
Copy link

half2me commented May 20, 2021

An ugly hack I've had to do is write a quick python script to strip the AppSync scalars and directives I've had to include.

import sys

schema_file = sys.argv[1]
aws_types_file = sys.argv[2]

with open(aws_types_file, 'r') as f:
    blacklist = list(filter(None, f.read().splitlines()))

with open(schema_file, 'r') as f:
    print('\n'.join(filter(
        lambda l: l not in blacklist,
        filter(None, f.read().splitlines())
    )))

I include all the AppSync scalars and directives in a graphql file, so the tool doesn't complain about missing types and whatnot, plus you get all the validation benefits. The only problem is, its now included in the output, which AppSync doesn't like, so I run this little script to remove it.

@kadishmal
Copy link

There is an option -d to include directives so the tool does not complain.

// .option('-d, --includeDirectives', 'By default will NOT merge the directives, unless you added this flag.', false)

@0xfourzerofour
Copy link

0xfourzerofour commented Dec 7, 2021

I have found that the following repository will work when you need appsync directives.

https://github.com/mattdamon108/gqlmerge

@tqhoughton
Copy link

Using AWS CDK I'm able to get the directives to upload to AppSync successfully by adding the -d flag like @kadishmal mentioned.

I have a "root.graphql" file where I define all of the base types for my API and just put the auth directives and scalars that I need in it. Here's an example:

# define all base types so when other files extend them you don't get errors
directive @aws_oidc on FIELD_DEFINITION | OBJECT
directive @aws_api_key on FIELD_DEFINITION | OBJECT

scalar AWSDateTime
scalar AWSDate
scalar AWSURL
scalar AWSEmail

type Query
@aws_oidc @aws_api_key
type Mutation
@aws_oidc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants