'How do I configure GraphQL Codegen to output a client that I can use in Node.js?

I have been using https://www.graphql-code-generator.com/ to generate TypeScript definitions, Apollo Hooks and resolvers for GraphQL for a while.

But now I would like it to generate Apollo client functions that I could use on Node.js

Node Example:

const { contacts } = await queryContacts(search: 'Jack');

for (const contact of contacts) {
  // ...
}

How do I configure codegen.yaml to generate an Apollo client function, similar to queryContacts?



Solution 1:[1]

add typescript-operation in plugins

for example:

overwrite: true
schema: "./apollo/schema.ts"
generates:
  lib/gen-types.ts:
    documents: ./queries/*.ts
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      reactApolloVersion: 3
      withHooks: true

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rayhk6