Hello,
I have a mutation:
mutation mutate($arg: String!) {
mutate @MyCustomDirective(arg: $arg) {
id
}
}
And I'm trying to run apollo:codegen with this config:
module.exports = {
client: {
service: {
name: 'name',
url: 'url',
includes: [`${__dirname}/packages/**/*.gql`],
headers: {
Authorization:
'Bearer token',
},
},
clientSchemaDirectives: [
'client',
'rest',
'MyCustomDirective',
],
},
};
Intended outcome:
Codegen should come through.
Actual outcome:
yarn apollo:codegen
Loading Apollo Project
Generating query files
.../mutate.gql: Unknown directive "MyCustomDirective".
How to reproduce the issue:
Add a custom directive to one of your .gql files, add it to clientSchemaDirectives, and run apollo:codegen.
Versions
With 2.17.4, it was working without having to specify
clientSchemaDirectives: [
'client',
'rest',
'MyCustomDirective',
],
Thanks in advance!
I was running into this issue with the @rest directive and I managed to fix it by manually defining the directive in my client side schema.graphql file like so:
directive @rest(
type: String!
path: String!
method: String
endpoint: String
bodyKey: String = "input"
) on FIELD
Also have this issue. I don't want to modify local schema because it's downloaded automatically from server.
Hack is to append the directive to downloaded schema during the automated process, which is not optimal but works:
"apollo:downloadSchema:local": "graphql get-schema -e local && yarn apollo:downloadSchema:addLocalDirectivesHack",
"apollo:downloadSchema:addLocalDirectivesHack": "cat localDirectivesHack.graphql.txt >> schema.graphql",
I get the same issue as @CodyBrouwers with @rest. I have defined the directive in my local schema file to get around one error, but I get this other error that the @client directive is missing:

I have not added clientOnlyDirectives or clientSchemaDirectives in my apollo config, but it doesn't work even if I add the default.
@evankennedy , the same is happening to me, and I wasn't able to fix. Does anyone know if there's a way of fixing this?
Just to add to the pile, looks like apollo's own code generator doesn't recognize apollo's own federation directives:
Unknown directive "key".
Unknown directive "external".
There's no reason why I'd have to supply anything external to make apollo's own tool work with their own schema/server and federation spec.
Most helpful comment
Just to add to the pile, looks like apollo's own code generator doesn't recognize apollo's own federation directives:
Unknown directive "key".
Unknown directive "external".
There's no reason why I'd have to supply anything external to make apollo's own tool work with their own schema/server and federation spec.