0
votes

I have a client-side schema in src/schema.graphql and some queries in src/graphql/queries.ts.

Currently, all my queries include @rest directive from apollo-link-rest and I am trying to generate Typescript types for them using apollo client:codegen with the following command:

apollo client:codegen ./src/__generated__/types.ts --outputFlat --includes=./src/**/queries.ts --addTypename --localSchemaFile=./src/schema.graphql --target=typescript

This always results in

.../src/graphql/queries.ts: Unknown directive "rest".
ToolError: Validation of GraphQL query document failed

I don't understand what I am doing wrong. According to the docs here Apollo should support @client and @rest client-side directives out of the box.

Has anyone successfully generated types for queries with @rest or @client directives?

1

1 Answers

0
votes

Hmmm, a bunch of documentation pages later and it seems if I declare the directive in src/schema.graphql as follows, it seems to work:

directive @rest(
    type: String!
    path: String!
    method: String
) on FIELD

Note: this declaration does not include all possible arguments. Refer to the docs for the complete list of arguments.

Can anyone confirm that this is the correct way of doing this?