Not able to create swift file from Graphqls file

For the mutation and query all working good, but when I add subscription It will not working.

Getting below error
GraphQLSchemaValidationError-Unknown directive “@aws_subscribe”.-GraphQLSchemaValidationError@

Hi @Mihir_Patel :wave:

The error is related to the @aws_subscribe directive you’re using. It is not a built-in directive of the GraphQL spec and it is not an Apollo iOS client directive so the codegen engine does not know how to handle it.

Directives must be specified in the schema file (typically the .graphqls file) before they can be used in any operation. The directive definition tells the Apollo iOS codegen engine where the directive can be used. Where do you get your schema from?

I have not seen the @aws_subscribe directive before but I did find this AWS documentation which describes it. I don’t see anything there about the directive definition though which makes me think it’s an AWS-specific directive and might get automatically added on their end.

Based on how it’s being used the directive definition might be something like the one below but you’ll need to find a way to get that into your schema file before code generation.

directive @aws_subscribe(mutations: [String!]!) on FIELD | FIELD_DEFINITION

Hi @calvincestari Thanks for the reply

I got this schema from AWS AppSync. I put below line in the graphqls file.

directive @aws_subscribe(mutations: [String!]!) on FIELD | FIELD_DEFINITION

Now I can able to generate the swift file. but when I called the subscription, It’s throw error

Websocket error: Unprocessed message {"type":"error","payload":{"errors":[{"errorType":"UnsupportedOperation","message":"unknown not supported through the realtime channel"}]}}. Error: nil"

I checked header, socket url, protocol all things is correctly configured,Still I am facing above issue.

Glad you managed to get code generation working. Based on that error I believe it’s coming from here in the WebSocketTransport code, which means that the AppSync server is returning the error. I don’t know what is causing that error but it does mention “UnsupportedOperation” so you’ll need to check with your schema and operations that what you’re wanting to subscribe to is supported.

Thanks for the your constant support,

Now the thing is I only add below line in schema file

directive @aws_subscribe(mutations: [String!]!) on FIELD | FIELD_DEFINITION

This same thing is working well in android. I do same as android pass the same header,protocol and all the other things, So now the difference is only above line which I added to the schema file. If I remove this line then swift file is not generated and If I put this line then connection not establish.

The directive definition is needed otherwise Apollo iOS does not know how to handle the directive. You need it in the schema.

I’m not sure why AppSync is returning the “UnsupportedOperation” error, you will need to check with them.

I already contact with their support team and they are saying contact Apollo Support.
As they are not able to solve @aws_subscribe directive issue for graphqls file.

As they are not able to solve @aws_subscribe directive issue for graphqls file.

You have solved this problem by adding the directive definition to the schema (graphqls file). You can now generate the Swift code.

The next problem is why the server returns you the error about “UnsupportedOperation”. There is no where in Apollo iOS where we generate that error.