0.1.41 • Published 2 days ago

@amazeelabs/codegen-operation-ids v0.1.41

Weekly downloads
-
License
MIT
Repository
-
Last release
2 days ago

GraphQL operation id generator

A GraphQL Codegen plugin to generate operation ids for your queries and mutations. Can be used with any request framework, be it react-query, urql or plain fetch.

Usage

Install the plugin and add it to your codegen.yml configuration file. When used on its own to generate a .json file, it will produce a query map that can be used by a GraphQL service to execute queries by id.

generated/map.json:
  documents:
    - ./graphql-files/**/*.gql
  plugins:
    - '@amazeelabs/codegen-operation-ids'

If it is applied in combination with typescript and typescript-operations to generate a .ts file, it will append utility types and an exported variable for each operation found. The variable itself is just the query id, but it is annotated with type information about input and output of the operation. This can be used to type the resulting requests based on the provided operation id.

generated/schema.ts:
  documents:
    - ./graphql-files/**/*.gql
  plugins:
    - typescript
    - typescript-operations
    - '@amazeelabs/codegen-operation-ids'
import {
  MyQuery,
  OperationResults,
  OperationVariables,
  AnyOperationId,
} from './generated/schema';

function graphqlFetch<T extends AnyOperationId>(
  id: T,
  variables: OperationVariables<T>,
): Promise<OperationResult<T>> {
  return fetch('/graphql', {
    method: 'POST',
    body: JSON.stringify({
      id,
      variables,
    }),
  }).then((response) => response.json());
}
0.1.41

2 days ago

0.1.40

2 days ago

0.1.39

3 days ago

0.1.38

26 days ago

0.1.37

1 month ago

0.1.36

2 months ago

0.1.35

3 months ago

0.1.33

4 months ago

0.1.34

4 months ago

0.1.30

4 months ago

0.1.31

4 months ago

0.1.32

4 months ago

0.1.29

4 months ago

0.1.28

4 months ago

0.1.27

6 months ago

0.1.26

6 months ago

0.1.22

11 months ago

0.1.23

7 months ago

0.1.24

7 months ago

0.1.25

7 months ago

0.1.21

11 months ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.10

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago