apollographql / apollo-tooling

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

unknown directive "connection" #275

Closed wakemaster39 closed 6 years ago

wakemaster39 commented 7 years ago

I am trying to implement pagination following the apollo documentation and it introduce the @connection directive for assigning a store key. Using apollo-codegen with the directive causes the Unkown directive "connection" error, which I understand is because it doesn't know about the directive.

Is defining the directive in the graphql schema the correct location that this needs to be defined or should the codegen know about the directive and handle the error?

0xcaff commented 6 years ago

Here's a similar issue with graphcool. #118

0xcaff commented 6 years ago

It looks like this issue was fixed for the eslint plugin (https://github.com/apollographql/eslint-plugin-graphql/issues/11), by disabling the directive validation until a better model was defined for client side only directives.

brianlovin commented 6 years ago

I'm encountering this same issue when going through the steps for codgen. My command:

apollo-codegen generate fragments/**/*.js --schema typegen-schema.json --target flow --output fragment-types.flow.js

My output:

/graphql/fragments/thread/threadMessageConnection.js: Unknown directive "connection".
error: Validation of GraphQL query document failed

And the fragment that's throwing this error:

export default gql`
  fragment threadMessageConnection on Thread {
    messageConnection(
      after: $after
      first: $first
      before: $before
      last: $last
    ) @connection(key: "messageConnection") {
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
      edges {
        cursor
        node {
          ...messageInfo
        }
      }
    }
  }
  ${messageInfoFragment}
`;

Is that eslint plugin a proper fix for this codegen issue? Or will I need to manually handle this connection directive?

brianlovin commented 6 years ago

Ah, looks like @0xcaff has a PR already inbound! https://github.com/apollographql/apollo-codegen/pull/359 - not a huge deal, but curious if there's a timeline on this. Otherwise I can run a custom fork for the short term :)

0xcaff commented 6 years ago

FWIW, I have this branch with the fixed, compiled version. https://github.com/0xcaff/apollo-codegen/tree/portable Just yarn add or npm install it.