apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 468 forks source link

clientSchemaDirectives is not working for apollo:codegen since 2.18.0 #1484

Open adrienharnay opened 5 years ago

adrienharnay commented 5 years ago

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

apollo@2.18.0

With 2.17.4, it was working without having to specify

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

Thanks in advance!

codybrouwers commented 4 years ago

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
slorber commented 4 years ago

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",
evankennedy commented 4 years ago

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.

guiccbr commented 4 years ago

@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?

dvelitchkov commented 4 years ago

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.