Apollo-tooling: clientSchemaDirectives is not working for apollo:codegen since 2.18.0

Created on 23 Aug 2019  路  5Comments  路  Source: apollographql/apollo-tooling

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

[email protected]

With 2.17.4, it was working without having to specify

    clientSchemaDirectives: [
      'client',
      'rest',
      'MyCustomDirective',
    ],

Thanks in advance!

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.

All 5 comments

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:
Screenshot from 2020-02-24 23-36-45

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rasmusprentow picture rasmusprentow  路  3Comments

hashlin picture hashlin  路  4Comments

atbtechgit picture atbtechgit  路  3Comments

ethansinjin picture ethansinjin  路  3Comments

u-ashish picture u-ashish  路  4Comments