1.0.8 • Published 4 years ago

codegen-apollo-bare-client v1.0.8

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

codegen-apollo-bare-client

GraphQL Code Generator plugin for bare Apollo client operations with full type-safety.

With support for all: query, mutation and subscription :tada:

Made for @apollo/client v3

Install

npm i codegen-apollo-bare-client
# or
yarn add codegen-apollo-bare-client

Install these if you don't already have them @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations

Usage

Inside your codegen.yaml, for example:

schema: schema.gql
documents: src/graphql/*.gql
generates:
  src/graphql/index.ts:
    plugins:
      - typescript
      - typescript-operations
      - codegen-apollo-bare-client
    config:
      # REQUIRED
      apolloClientImport: 'import { client } from "../apolloClient"'
      # "apolloClientName" is optional, by default looks for "client"
      # Just make sure it's the same name as in the import
      apolloClientName: client
# Optional prettier usage
hooks:
  afterAllFileWrite:
    - prettier --write src/graphql/*

And if you have for example:

query posts($limit: Int!) {
  posts(limit: $limit) {
    title
    body
  }
}

Reusing the typescript and typescript-operations generated code, it will generate functions like these:

export const postsClientQuery = (
  opts: Omit<QueryOptions<PostsQueryVariables>, "query"> & {
    variables: PostsQueryVariables;
  }
) => {
  return client.query<PostsQuery, PostsQueryVariables>({
    query: PostsDocument,
    ...opts,
  });
};
1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago